Ruby on Rails: Using Full Text Search with Tagging

I’m working on a new application in Rails that uses both Tagging as well as full text indexing. I decided to go with Ferret, which is just a Ruby port of Lucene. Using the acts_as_ferret plugin, it’s dead simple to integrate into your application. First, you want to install Ferret on your machine, and then run this command:


script / plugin install svn :// projects . jkraemer . net / acts_as_ferret / tags / stable / acts_as_ferret

At this point, you are ready to start enabling searching on your objects. Let’s say you want to enable full text search through a list of blog posts in your application. All you need is to add the acts_as_ferret line to your model class.


class Post < ActiveRecord :: Base acts_as_ferret end

And there you have it, full text indexing is enabled. To search through your objects, you’ll do nothing more than this:


Post . find_by_contents( " Agile Rails " )