Sphinx Search

7
Dec

Acts as taggable on and Thinking Sphinx Integration


Using thinking sphinx to search objects that are tagged using the acts_as_taggable_on plugin.

class Photo < ActiveRecord::Base
  ...
 
  acts_as_taggable_on :keywords
 
  define_index do
    indexes :caption
    indexes keywords.name, :as => :keywords
  end
 
  ...
end

Now lets assign some tags to our Photo

>> photo = Photo.create :user_id => 1, :caption => 'BMW M7', :keyword_list => 'BMW, Car'
>> photo.keywords
=> [#<Tag id: 1, name: "BMW">, #<Tag id: 3, name: "Car">]

Lets run the indexer

 

Syndicate content