acts_as_ferret

This ActiveRecord mixin adds full text search capabilities to any Rails model.

It is heavily based on the original acts_as_ferret plugin done by Kasper Weibel and a modified version done by Thomas Lockney, which both can be found on ferret.davebalmain.com/trac/wiki/FerretOnRails

Project Wiki and Issue tracker

wiki.github.com/jkraemer/acts_as_ferret/ j-k.lighthouseapp.com/projects/45560-acts-as-ferret

Installation

Aaf is available as a gem (gem install acts_as_ferret), or via git from github.com. Github also offers tarball downloads, check out github.com/jkraemer/acts_as_ferret/tree/master .

Set up your Rails > 2.1 project to use the acts_as_ferret gem.

Add this to your project’s config/environment.rb:

config.gem 'acts_as_ferret', :version => '~> 0.4.7'

With Rails 3 of course instead you have to update your Gemfile, but I guess you already knew that ;-) With the gem installed, change into your RAILS_ROOT and run the supplied aaf_install script. This will copy rake tasks, capistrano recipes and the ferret server config and startup script into your project.

In order to have the capistrano recipe loaded you’ll have to patch your Capfile a bit. I use to have a line like that in my Capfiles, loading everything found below RAILS_ROOT/lib/recipes:

Dir['lib/recipes/*/.rb'].each { |plugin| load(plugin) }

Installation inside your Rails project via script/plugin

script/plugin install git://github.com/jkraemer/acts_as_ferret.git

No additional setup needed.

Usage

include the following in your model class (specifiying the fields you want to get indexed):

acts_as_ferret :fields => [ :title, :description ]

now you can use ModelClass.find_with_ferret(query) to find instances of your model whose indexed fields match a given query. All query terms are required by default, but explicit OR queries are possible. This differs from the ferret default, but imho is the more often needed/expected behaviour (more query terms result in less results).

Please see ActsAsFerret::ActMethods#acts_as_ferret for more information.

License

Released under the MIT license.

Authors

  • Kasper Weibel Nielsen-Refs (original author)

  • Jens Kraemer <[email protected]> (current maintainer)