Search code examples
ruby-on-railssphinxthinking-sphinx

Adding meta descriptions to thinking sphinx objects?


Is there any simple way for ThinkingSphinx to index some meta data keywords along with each object being indexed.

In the example below, I'am indexing the photos table here which contains photos from different locations.

ThinkingSphinx::Index.define :photo, :with => :active_record do
  indexes title, description, continent, country, province, area
end

Now if i search for a location e.g 'bhutan', sphinx gives me all the photos and other items associated with Bhutan. But if i search for 'bhutan photos' then sphinx does not return anything since the keyword 'photo' is not indexed along with the items in the photos table.

One way for me to solve it would be to add a 'searchmeta' column in my photos table and put the descriptive keywords in that column entry. But this is very expensive because the same information will be duplicated all the rows of my photos table. I would like to know if there is any simpler way around this problem?


Solution

  • As Barry's suggested in the comments, you could just strip that information from the metadata keywords from queries - that might be best, but another option is you can add it directly into the index definition as a string (skipping the need to have it in the database):

    ThinkingSphinx::Index.define :photo, :with => :active_record do
      indexes title, description, continent, country, province, area
      indexes "'photo photos'", :as => :metadata
    end