views:

170

answers:

1

Hypothetically, I have a Room model that belongs to a Building model. Buildings has a has_many relationship with categories.

I'm trying to figure out how to index the Room model so that a search for category_id = 1 will return any room, in any building that happens to have that category assigned to it. Again, a building can have multiple categories.

thanks!

+4  A: 

Firstly, you'll want to set up your index something like the following in your Post model:

define_index do
  # fields go here

  # the important attribute for your filter:
  has building.categories(:id), :as => :category_ids
end

As for searching:

Room.search 'query', :with => {:category_ids => 1}

Let me know if this isn't quite what you're after.

pat