Gmane
From: Luke Randall <luke.randall@...>
Subject: RFC: How best to integrate Ferret with a Rails project
Newsgroups: gmane.comp.lang.ruby.rails
Date: 2005-10-26 10:02:49 GMT (3 years, 36 weeks, 17 hours and 14 minutes ago)
All

I've been using Ferret for the past few days and have been wondering
how best to integrate it with Rails. Initially I just setup the
following in my environment.rb file:

require 'ferret'
import Ferret

@@index = Index::Index.new()

However, this felt very unclean to me, so I decided the best way to do
it would be to create a separate model like this:

require 'singleton'
require 'ferret'

class CompanyIndex
  include Singleton
  include Ferret

  SEARCH_INDEX = "#{RAILS_ROOT}/db/index.db"

  def initialize
    @index = Index::Index.new(:path => SEARCH_INDEX)
  end

  def search
  # search code
  end

  def add
  # code to add to index
  end
end

etc. I then access it using CompanyIndex.instance.

Now, is this the best way to do this? Are there cleaner ways of integrating it?

Also, since Ferret requires a lock on the index, am I correct in
assuming that having multiple Rails dispatch threads running would not
work?

Luke