Closed pat closed 1 month ago
@pat Sadly, this doesn’t quite work as expected. The problem is that it only considers ActiveRecord::Base
but none of models inheriting from it. Thus, it still explodes with the following error
ArgumentError: You tried to define a scope named "search" on the model "Content", but Active Record already defined a class method with the same name. (ArgumentError)
raise ArgumentError, "You tried to define a scope named \"#{name}\" " \
This approach will always add the following methods to ActiveRecord::Base:
sphinx_search
sphinx_search_for_ids
sphinx_search_count
sphinx_facets
And then, if there aren't methods already existing without the
sphinx_
prefix, they're also added:search
search_for_ids
search_count
facets
This does not remove the possibility that something invoked after Thinking Sphinx will overwrite the
search
method, etc - but at least thesphinx_
-prefixed versions will always be available.This addresses #1264 and is an evolution of #1241.