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.