Sphincter 1.1.0
With a Rails app running in development mode, classes by default are not cached.
Sphincter::Search.indexes is a hash of classes-to-be-indexed mapped to their indexing options.
The Sphincter::Search.add_index method, which is mixed into ActiveRecord::Base, adds any model class with an add_index
declaration to the Sphincter::Search.indexes hash.
The problem arises when a model class with an add_index is loaded more than once by Rails (in development mode). Rails
does not cache model class definitions, so each new version of, say, the User class has a different object_id. And
that causes the add_index method to add each new version to the Sphincter::Search.indexes hash.
This then breaks the mapping from sphinx id to database id, because the index_count is too high.
Here is a solution that works for me(TM):
In the file Sphincter-1.1.0/lib/sphincter/search.rb, the final line of the method add_index(options = {}) is:
Sphincter::Search.indexes[self] << options
I make this conditional on a class with the same name as self not being in the hash:
unless Sphincter::Search.indexes.keys.any? { |klass| klass.class_name == self.class_name }
Sphincter::Search.indexes[self] << options
end
This doesn't break any tests.
|