Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Search Rails models with fuzzy matching for words
branch: master
Failed to load latest commit information.
lib Whoops, minor indentation mistake
MIT-LICENSE Initial import from…
README Make fuzzy_search play nice with eager loading
Rakefile Initial import from…
init.rb Initial import from…
install.rb Initial import from…
uninstall.rb Initial import from…


Search through your models while tolerating slight mis-spellings. If you have a Person in your database named O'Reilly, you want your users to be able to find it even if they type "OReilly" or "O'Rielly".

NOTE! The following plugin is a prerequisite:
  script/plugin install git://
More details at


class Person < ActiveRecord::Base
  # ...
  include FuzzySearch
  fuzzy_search_attributes :name, :surname
  # ...

people = Person.fuzzy_find "OReilly"

# Fuzzy find works on scopes too. This includes named_scopes.
people = Person.scoped({:conditions => ["state='active'"]}).fuzzy_find("OReilly")

If you define a methods returning a string

  def self.normalize(word)

before include the FuzzySearch than this method gets used to normlize any word. default is to downcase the string (which does only work properly within ascii)

Trigrams table

For each model that you want to fuzzy-search, you have to define a Trigram model and table, using the following example:

  create_table "person_trigrams", :force => true do |t|
    t.integer "person_id"
    t.string  "token",   :null => false

  # The PersonTrigram model itself
  class PersonTrigram < ActiveRecord::Base

==Licence and credits==
This plugin is inspired by the following blog entry

The code is based off the act_as_fuzzy_search plugin for DataMapper
by mkristian (

This plugin is available under the MIT Licence.

Something went wrong with that request. Please try again.