Reputation: 4628
My model is indexed with Thinking Sphinx and I am wanting to filter search results by the model's tags—provided by acts_as_taggable_on. I read this previous question, which enabled my searches to use :conditions => { :tags => 'Comedy' }
as a filtering query.
This is not a catch-all solution, since by default all text is searched in Sphinx's indexed fields. For example, when I search Model.search :conditions => { :tags => "Comedy" }
, results with the tag Black Comedy
also appear. I see that using attributes instead of fields is a solution, but I cannot seem to get valid results when searching Model.search :with => { :tags => "Comedy" }
and my define_index
block looks like this:
define_index
indexes title, :sortable => true
has category_tags(:name), :as => :tags
end
Note that I am building upon the previous answer provided in the question linked above. The answerer details indexing tags within context—thus the reason for the category_tags method.
Upvotes: 0
Views: 576
Reputation: 2349
Change your index to:
define_index
indexes title, :sortable => true
has "CRC32(category_tags.name)", :as => :tags, :type => integer
end
Note: category_tags.name refers to your_table_name.column_name
And search the tag after converting to int:
Model.search :with => {:tags =>'Comedy'.to_crc32}
See common questions for more: http://freelancing-god.github.com/ts/en/common_issues.html
Upvotes: 3