Jerome
Jerome

Reputation: 6189

Combining free text and object ids with thinking sphinx

The following index will allow free text searches on the given model's attributes:

ThinkingSphinx::Index.define :firm, :with => :active_record do
  indexes activity
  indexes city
end

for a form that allows input in <%= text_field :firm_search, :terms, :size => 35 %>

However, this class belongs_to :province, thus has a province_id column and class Province has a :name attribute that could be composed of more than one, hopefully, searchable word. Can province.name be integrated into this free text search?

Upvotes: 0

Views: 29

Answers (1)

pat
pat

Reputation: 16226

Yes, you can reference associations within your index definition:

ThinkingSphinx::Index.define :firm, :with => :active_record do
  indexes activity
  indexes city
  indexes province.name, :as => :province_name
end

Once you've added this, you'll need to run the ts:rebuild rake task to have the data included in your Sphinx indices.

Upvotes: 1

Related Questions