Note: This feature is available in version 1.2 or later
One of the popular features of ActiveRecord is named scopes. You can try using them with searches, but they will not impact search results, just the SQL queries used to gather the ActiveRecord objects - Sphinx itself does not use SQL for querying.
However, Thinking Sphinx now has sphinx scopes, which work in pretty much the same manner.
To add a scope to the model, use the
sphinx_scope method. This should
be called within the class definition, not the define_index block.
named_scope, you can use arguments if you need to.
Once you have set up your scopes, you can use them on your model, just like you would use ActiveRecord’s named scopes.
The search call is optional, if you don’t actually have any extra arguments to pass in.
Feel free to add to the chain at any point - Thinking Sphinx won’t populate the search results until you actually need them.
default_sphinx_scope method allows a sphinx scope to always be
used when searching a model. This can be useful if all searches on a
model require the scope is used.