Skip to content

Commit

Permalink
Added config.search.engine = thinking_sphinx
Browse files Browse the repository at this point in the history
    config.search.model_name = product
  • Loading branch information
Hans Masing committed Oct 9, 2010
1 parent eead524 commit 634eb72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README
Expand Up @@ -41,6 +41,11 @@ in your active_scaffold config block:

That's it!

Super-advanced configuration: If you want to specify the model you will be searching on (since by default it is derived from the current controller), add the following option:

config.search.model_name = 'product'


Copyright (c) 2010 Cory Patterson, released under the MIT license
Copyright (c) 2010 Hans Masing, released under the MIT license

20 changes: 18 additions & 2 deletions lib/as_thinking_sphinx.rb
Expand Up @@ -22,8 +22,20 @@ def engine
def engine=(val)
@engine = val
end
end

# Add the 'model_name' configuration option
def model_name
unless @model_name
@model_name
self.model_name = nil
end
@model_name
end

def model_name=(val)
@model_name = val
end
end


ActiveScaffold::Actions::Search.class_eval do
Expand All @@ -40,7 +52,11 @@ def do_search
unless @query.empty?
begin
# Run the search, returning only the ids
sphinx_results = self.controller_name.classify.constantize.search(@query, :select => :id, :limit => 50)
active_scaffold_config.search.model_name.nil? ? @model_name = self.controller_name : @model_name = active_scaffold_config.search.model_name

puts "\n\n\n\n\n\n\n\n\n#{@model_name}\n\n\n\n\n\n\n\n\n\n"

sphinx_results = @model_name.classify.constantize.search(@query, :select => :id, :limit => 50)
# puts sphinx_results.collect { |x| x.id }
rescue NoMethodError
# There is no search method on the model, probably no indexes configured
Expand Down

1 comment on commit 634eb72

@coryp
Copy link

@coryp coryp commented on 634eb72 Mar 23, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged Hans Masing's additions

Please sign in to comment.