Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fun experiment in parsing search query strings (like Pivotal Tracker does)
branch: master
Failed to load latest commit information.
lib Move search methods to be evaluated when the class is loaded
spec Move search methods to be evaluated when the class is loaded
tmp Keep the tmp directory, just ignore the log
Gemfile Fix name of sqlite3 gem
Gemfile.lock Bump to AR 4.2, remove 'richard' code Rename external to label everywhere.
Rakefile first commit
license.txt added license file
searcher.gemspec Bump to AR 4.2, remove 'richard' code
searcher.sqlite3 Configure to use ActiveRecord 4.0, version bump


Searcher is a pure SQL implementation which lets you find by pre-defined labels, as well as wildcard matching queries. It should be used as a lo-fi precursor to a proper full-text search platform, such as the built-in one to PostgreSQL.

The idea of this gem came from Joost Schuur.

This gem is used in Chapter 10 of Rails 3 in Action and was crafted specifically for it. YMMV.


This gem is only compatible with versions of Active Record that are greater than or equal to 3.0. You are using Active Record 3, right?

Add this gem to your Gemfile (You are using Bundler, right?):

gem 'searcher'


To define labels for your field, use the searcher method inside your model like this:

class Ticket < ActiveRecord::Base
  has_and_belongs_to_many :tags

  searcher do
    label :tag, :from => :tags, :field => "name"
    label :state, :from => :state, :field => "name"

To query for these labels, use the search class method on your model:"tag:v3.0.0 state:open")

Boom! There's all your tickets that have the tag v3.0.0 and are marked (state-wise) as being open.


Currently Searcher works only with has_and_belongs_to_many and belongs_to associations, as that is all that is needed in the book.

Something went wrong with that request. Please try again.