sunspot/sunspot — pull request #251 by brutuscat (2012-06-20 11:14:41+00:00)
Title: Searchable classes now can inherit #search options

A squeezed version of #195 to be reviewed by all. /cc @alindeman

When using STI in Rails, sometimes there is the need to keep DRY some searches. So instead of having one search per sibling Models, it is now possible to search on the parent model AND pass options to it. Example:

```ruby
Event < BaseDataMapper
belongs_to :location

searchable {...}

def search_something
self.search(:include => [:location]){ fulltext "bla" }
end
end

MovieEvent < Event
end

```

Now when calling `movie_event.search_something`, it will have included the location as it was set in the parent search call.

I already added this behavior the the ActiveRecordDataAccessor, but any other DataAccessor can make use of it.

This was done in to allow easy eager-loading when grouping/folding. Say that you need to do a folded/grouped search for events. The events are of different classes (Movie, Play, Show) but share a common parent (Event). Also you need to eager load those results to speed up rendering. Now you can search on the Event with an :include, and all the DataAccessors for the "child" classes will have injected the :include option.
Then you can call the, also new, #populate_all_hits on the group you want like this `@search.group(:location_name_str).populate_all_hits` to eager load those events.

If everything is Ok I will commit this tomorrow ;)