Jens Krämer

Rails full text search, version 0.2.2

 |  ferret, ruby, rails

It took quite some time, but finally I got version 0.2.2 of the acts_as_ferret Rails plugin out of the door.

The most important change is the support for sharing a single index among several model classes.

It’s as simple as calling acts_as_ferret :single_index => true

in those Rails models you intend to share one index.

Querying the shared index for instances of one class, any combination of model classes, or all classes works like this: # only find instances of Model1 Model1.find_by_contents(query)

only find instances of Model1, Model3 and Model4

Model1.find_by_contents(query, :models => [Model3, Model4])

find instances regardless of their class

Model1.find_by_contents(query, :models => :all) </code>

So acts_as_ferret now covers these setups, including various combinations thereof:

  • multiple indexes, one per model class (however multi_search allows querying multiple indexes at once)
  • one index, multiple models using single table inheritance (base class calls acts_as_ferret)
  • one index that is shared by multiple unrelated models through :single_index => true

One limitation: there may be only one shared index in an application.

Another new feature: you may now call total_hits on the search results returned by acts_as_ferret search methods to find out how many hits your query returned in total.

As usual, you can use

script/plugin install svn://

to install the lates version of the plugin. For more information, repository browsing or issue reporting, visit the Acts_as_ferret project page.

For further information about the great Ferret search engine by Dave Balmain, visit the Ferret project page.