README.rdoc

Scoped search

The scoped_search Rails plugin makes it easy to search your
ActiveRecord models. Searching is performed using a query string, which
should be passed to the named_scope search_for. Based on a
definition in what fields to look, it will build query conditions and
return those as a named scope.

Scoped search is great if you want to offer a simple search box to your
users and build a query based on the search string they enter. If you want
to build a more complex search form with multiple fields, searchlogic (see
github.com/binarylogic/searchlogic)
may be a good choice for you.

Installing

The recommended method to enable scoped search in your project is adding
the scoped_search gem to your environment. Add the following code to your
Rails configuration in config/environment.rb, and run rake
gems:install to install the gem.:

Rails::Initializer.run do |config|
...
config.gem 'scoped_search'
end

Alternatively, install scoped search as a Rails plugin (deprecated):

script/plugin install git://github.com/wvanbergen/scoped_search.git

Usage

Scoped search requires you to define the fields you want to search in:

Now, the search_for scope is available for queries. You should pass
a query string to the scope. This can be empty or nil, in which case all no
search conditions are set (and all records will be returned).

User.search_for('my search string').each { |user| ... }

The result is returned as named_scope. Because of this, you can
actually chain the call with other scopes, or with will_paginate. An
example: