Saturday, October 28, 2006

rails text search

This tutorial shows you how to search your data at your Rails application. we will use an easy, and flixible plugin called ferret.

ready? follow up:
  • install ferret gem:
gem install ferret
  • install ferret plugin:
script/plugin install svn://projects.jkraemer.net/acts_as_ferret/tags/stable/acts_as_ferret
  • at your model add the following line:
act_as_ferret or customize your search to only some fields like this: act_as_ferret :fields => [:name, :firstname, :surename]
  • now your database fields are searchable.
to search your data type: .find_by_contents("osama OR dwairi") and walk through them as array

2 comments:

nzahn said...

I wondered if ferret is able to be used with ajax (instant feedback), if so, how? Any idea?

dwairi said...

sure, your search is up to date with ferret since it do indexing on the save/update time of any object of your model that is marked as acts_as_ferret.

you can view the ferret logging on your log file log/{the_environment_you_use}.log

- Osama