Wednesday, March 14, 2007

Pitfalls of acts_as_ferret, with DrbServer to the rescue

I don't know how general this case is, but I've found that if you want to use acts_as_ferret in your production Rails app, you need to run your Ferret server as a separate DrbServer process.

Background

acts_as_ferret gives you a powerful search capability, and it's much easier to implement than MySQL full text querying.

Numerous tutorials (here and here) describe how to do this. In development mode, it's as simple as adding something like this to your model:

acts_as_ferret :fields => [ :city, :state ]

and this to your controller:

@users = User.find_by_contents(params[:keywords])

Problem

I started getting all kinds of corrupted index errors when I put this into production, because acts_as_ferret can't handle multiple separate processes access the index at once. This caused a lot of scrambling as I was starting to get a lot of traffic.

Solution

Fortunately I discovered that acts_as_ferret comes with its own built-in DrbServer. As soon as I set that up, everything worked great.

The developer does a great job explaining what to do. You add :remote => true to your acts_as_ferret declaration, setup a ferret_server.yaml config file, then run:

RAILS_ENV=production script/runner vendor/plugins/acts_as_ferret/script/ferret_server

...and you're golden.

UPDATE: To make the acts_as_ferret unit tests run correctly, add the following line to your test/environment.rb file:

AAF_REMOTE = true

Labels: ,

8 Comments:

At April 1, 2007 4:48 AM , Anonymous Anonymous said...

Hi,just a quick note: the AAF_REMOTE variable isn't needed unless you want to run the unit tests of acts_as_ferret with the DRb server.

 
At April 9, 2007 2:40 PM , Blogger Mike said...

Thanks -- I updated the post to make that more clear!

 
At June 19, 2008 7:16 AM , Blogger Johannes Fahrenkrug said...

If you don't want to use the drb server for your tests, but want them to run correctly anyway, see this blog post: Unit testing with acts_as_ferret

 
At July 4, 2008 12:36 AM , Blogger Ravi Vardhan said...

Hi,

I got the same problem with ferret.
but i cann't understand online in your solution.

RAILS_ENV=production script/runner vendor/plugins/acts_as_ferret/script/ferret_server

how to run this server?

before my rails server(apache) or when and where this command i use?

please give me explanation for this.

thanks,

 
At August 26, 2008 12:18 PM , Anonymous Gideon said...

I try to run:

script/ferret_server -e production start

on my production system and it says:

can't convert nil into String

Any ideas how to track this down? It works fine on my development system (MacOS X), and I have copied the complete project over to the production system (FreeBSD), and installed ferret using the gem.

Any help would be greatly appreciated.

 
At March 16, 2009 3:17 PM , Blogger leonardo said...

Does anyone knows how to solve Gideon problem (error: can't convert nil into string?).

 
At April 15, 2009 10:35 PM , Blogger internetchris said...

I am having the same problem. I try to run "ruby script/ferret_server start" as outlined in the Advanced Rails Recipe book, and I get the message
"can't convert nil into String".

I am using instantrails, and windows vista.

 
At April 17, 2009 1:26 PM , Blogger Mike Subelsky said...

sorry, not sure what would cause this not to work on Windows

 

Post a Comment

Links to this post:

Create a Link

<< Home