Fetching contributors…
Cannot retrieve contributors at this time
63 lines (42 sloc) 1.58 KB

This is a DataMapper plugin for Ferret.

Setup code

For a single process site, use the ferret index directly:

DataMapper.setup :search, "ferret:///path/to/index"

For a multi-process site, use the distributed index by running `ferret start` inside your project's directory and then setting up the :search repository:

DataMapper.setup :search, "ferret:///tmp/ferret_index.sock"

Sample Code

require 'rubygems' require “dm-core” require “dm-is-searchable”

DataMapper.setup(:default, “sqlite3::memory:”) DataMapper.setup(:search, “ferret://#{Pathname(__FILE__).dirname.expand_path.parent + ”index“}”)

class Image

include DataMapper::Resource
property :id, Serial
property :title, String

is :searchable # this defaults to :search repository, you could also do
# is :searchable, :repository => :ferret


class Story

include DataMapper::Resource
property :id, Serial
property :title, String
property :author, String

repository(:search) do
  # We only want to search on id and title.
  property :id, Serial
  property :title, String

is :searchable


Image.auto_migrate! Story.auto_migrate! image = Image.create(:title => “Oil Rig”); story = Story.create(:title => “Big Oil”, :author => “John Doe”) }

puts => “Oil Rig”).inspect # => [<Image title=“Oil Rig”>]

# For info on this, see DM::Repository#search and DM::Adapters::FerretAdapter#search. puts repository(:search).search('title:“Oil”').inspect # => { Image => [“1”], Story => [“1”] }


puts => “Oil Rig”).inspect # => []