algolia/algoliasearch-rails — pull request #11 by zapnap (2014-01-31 23:55:45+00:00)
Title: support single table inheritance / subclasses (via parent index)

If I declare algoliasearch with some options on a base class that has several subclasses, the subclasses will get indexed appropriately -- as part of the parent index. However, I run into a problem when I try calling index! or reindex! on a subclass instance.

def algolia_index!
self.class.algolia_index!(self, algolia_synchronous?)
end

def algolia_remove_from_index!
self.class.algolia_remove_from_index!(self, algolia_synchronous?)
end

This is because we're referencing @algolia_options and other ivars on the class in question, which is of course not the parent class (where it was defined), so it's unavailable. This PR fixes it by making algolia options and settings available (via method on the parent class) to all the subclasses.

One gotcha here is that you still won't be able to do a SubclassModel.search 'something' to find *only* results of that subclass, but it's a first effort that adds some necessary behavior.