Repository is archived
No commit activity in last 3 years
No release in over 3 years
Ferret Adapter for DataMapper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6.4
~> 0.9.2
~> 1.3.2
~> 2.1.2

Runtime

~> 1.2.0
~> 0.11.6
 Project Readme

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

end

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.
  properties(:search).clear
  property :id, Serial
  property :title, String
end

is :searchable

end

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

puts Image.search(:title => “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”] }

image.destroy

puts Image.search(:title => “Oil Rig”).inspect # => []