[jifty-devel] [fwd] [geek] Rails acts_as_ferret rocks my world! (from: eric.kidd)

jesse jesse at fsck.com
Fri Jul 7 15:04:31 EDT 2006

I want this :)

----- Forwarded message from Eric Kidd ----

Date: Fri, 7 Jul 2006 14:57:33 -0400
From: Eric Kidd
To: "A list for people with geeky interests." 
Subject: [geek] Rails acts_as_ferret rocks my world!

OK, now to say something nice about somebody's software. :-)

Today, I added full text indexing to a Rails application.  Here are the 

 $ sudo gem install ferret
 $ script/plugin install

Edit my Ticket class to add the following code:

 acts_as_ferret :fields => %w(title created_at updated_at)

Edit my Update class to add the following code:

 acts_as_ferret :fields => %w(comment created_at user updated_fields)

 # Support for ferret indexing of non-standard fields.
 def content_for_field_name name
   case name.to_sym
   when :user
   when :updated_fields
     updated_fields.map {|f| "#{f.from} #{f.to}" }.join(", ")

Then I ran script/console, and typed in the following queries:

 >> Ticket.find_by_contents("search").length
 => 1
 >> Ticket.find_by_contents("search")[0].title
 => "Basic search implementation"
 >> Update.find_by_contents("Unicode").length
 => 2

acts_as_ferret automatically built fast, full-text indices for all the
records in my database, and keeps them up to data.  The query language
is user-friendly, too.

This is how quality software should work. :-)

-Eric, delighted by how painless that was

----- End forwarded message -----


More information about the jifty-devel mailing list