Giter VIP home page Giter VIP logo

dm-ferret-adapter's Introduction

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 # => []

dm-ferret-adapter's People

Contributors

bernerdschaefer avatar dkubb avatar myabc avatar namelessjon avatar paul avatar snusnu avatar solnic avatar somebee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.