Prev | Current Page 252 | Next

Brad Ediger

"Advanced Rails"

It is
available from http://ferret.davebalmain.com/trac/. It has a great reputation and is
almost infinitely configurable. It keeps most of Lucene??™s API, so it will be more familiar
to Java programmers.
170 | Chapter 6: Performance
Jens Kr?¤mer??™s acts_as_ferret library (http://projects.jkraemer.net/acts_as_ferret/)
makes it quite a bit easier to use Ferret to search an ActiveRecord model. The basic
procedure is as follows:
1. Install the Ferret library as a gem:
$ sudo gem install ferret
2. Install acts_as_ferret as a Rails plugin:
$ script/plugin install \
svn://projects.jkraemer.net/acts_as_ferret/tags/stable/acts_as_ferret
3. Add the acts_as_ferret call to any model that should be indexed. The :remote =>
true option directs acts_as_ferret to connect to a central Ferret server over DRb;
this option is required when using multiple application servers:
class Product < ActiveRecord::Base
acts_as_ferret :fields => [:title, :description, :product_number],
:remote => true
end
4. Use the find_by_contents class method to query the index:
results = Product.find_by_contents "toaster"
5. If a manual reindex is necessary, use the rebuild_index class method:
Product.rebuild_index
For those of us who are only killing flies, and thus don??™t need a sledgehammer,
Mauricio Fern??ndez has a solution: FTSearch. Although it does not have many of
the features that Ferret provides, it is much lighter (about 3% of the size, as measured in
lines of code) and it has the most commonly used features.


Pages:
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264