github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

mkristian / kristians_rails_plugins

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 7
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

share my private rails plugins: fuzzy-search, datanmapper-session-store, idle-session-timeouts, etc — Read more

  cancel

<a href="http://code.google.com/p/kristians-rails-plugins">code.google.com/p/kristians-rails-plugins</a>

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

added some notes on the future of the project 
mkristian (author)
Sun Nov 29 08:42:58 -0800 2009
commit  6aa38bb8dd01dbaafad59f4fe09f5e4f10affb93
tree    bf1c0e9a1781c1da2c3db03a0843e39fa59237aa
parent  709242854aca2119aa59d0dad80cc54da80037ce
kristians_rails_plugins / act_as_fuzzy_search
name age
history
message
..
file MIT-LICENSE Loading commit data...
file MIT-LICENSE~
file README
file README~
file Rakefile
file init.rb
file init.rb~
file install.rb
directory lib/ Mon Dec 15 03:40:33 -0800 2008 cleaned up rubbish [mkristian]
directory tasks/ Mon Dec 15 03:40:33 -0800 2008 cleaned up rubbish [mkristian]
directory test/ Mon Dec 15 03:40:33 -0800 2008 cleaned up rubbish [mkristian]
file uninstall.rb
act_as_fuzzy_search/README
ActAsFuzzySearch
================

this plugin is inspired by the following blog entry
http://unirec.blogspot.com/2007/12/live-fuzzy-search-using-n-grams-in.html
it can add a fuzzy search to model. this search needs another table where all the
trigrams are stored but that table is hidden otherwise.

the whole plugins does not work with ActiveRecords, but for Datamapper !! to get it to work
for ActiveRecord only a few code places need to be changed, I marked the in the code #DM.

configuration
=============

add the following in the model class

  include FuzzySearch

  act_as_fuzzy_search :property1, :property1
  
where :property1, :property2 are the properties which are index for the fuzzy search. each property gets split into 
words (separator is the whitespaces)

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 downcast 
the string (which does only work properly within ascii)

trigrams table
==============

the naming follows the convention

class <model_classname>Trigram

  property :id, Integer, :serial => true

  property :<model_lowercase>_id, Integer, :index => true

  property :token, String, :nullable => false, :length => 3, :index => true

end

example
=======

class UserTrigram

  include DataMapper::Resource

  property :id, Integer, :serial => true

  property :user_id, Integer, :index => true

  property :token, String, :nullable => false, :length => 3, :index => true

end

the model class looks like this

class User

  include DataMapper::Resource

  def self.normalize(word)
     #TODO something
     word.downcase
  end

  include FuzzySearch

  act_as_fuzzy_search :firstname, :surname
  
  property :id, Integer, :serial => true

  property :surname, String, :nullable => false , :format => /^[^<'&">]*$/, :length => 32
  property :firstname, String, :nullable => false , :format => /^[^<'&">]*$/, :length => 32

end

now you can create users and search them in a fuzzy manner like

  User.fuzzy_find("Heywy")

enjoy !!

Copyright (c) 2008 kristian, released under the MIT license
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server