Class: DataMapper::Adapters::SphinxAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/dm-sphinx-adapter/sphinx_adapter.rb

Overview

Synopsis

DataMapper uses URIs or a connection has to connect to your data-stores. In this case the sphinx search daemon searchd.

On its own this adapter will only return an array of document IDs when queried. The dm-more source (not the gem) however provides dm-is-searchable, a common interface to search one adapter and load documents from another. My suggestion is to use this adapter in tandem with dm-is-searchable.

The dm-is-searchable plugin is part of dm-more though unfortunately isn’t built and bundled with dm-more gem. You’ll need to checkout the dm-more source with Git from git://github.com/sam/dm-more.git and build/install the gem yourself.

git clone git://github.com/sam/dm-more.git
cd dm-more/dm-is-searchable
sudo rake install_gem

Like all DataMapper adapters you can connect with a Hash or URI.

A URI:

DataMapper.setup(:search, 'sphinx://localhost')

The breakdown is:

"#{adapter}://#{host}:#{port}/#{config}"
- adapter Must be :sphinx
- host    Hostname (default: localhost)
- port    Optional port number (default: 3312)
- config  Optional but recommended path to sphinx config file.

Alternatively supply a Hash:

DataMapper.setup(:search, {
  :adapter  => 'sphinx',       # required
  :config   => './sphinx.conf' # optional. Recommended though.
  :host     => 'localhost',    # optional. Default: localhost
  :port     => 3312            # optional. Default: 3312
  :managed  => true            # optional. Self managed searchd server using daemon_controller.
})

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, uri_or_options) ⇒ SphinxAdapter

Initialize the sphinx adapter.

Parameters:

  • uri_or_options (URI, DataObject::URI, Addressable::URI, String, Hash, Pathname)

See Also:



51
52
53
54
55
56
# File 'lib/dm-sphinx-adapter/sphinx_adapter.rb', line 51

def initialize(name, uri_or_options)
  super

  managed = !!(uri_or_options.kind_of?(Hash) && uri_or_options[:managed])
  @client  = managed ? SphinxManagedClient.new(uri_or_options) : SphinxClient.new(uri_or_options)
end

Instance Attribute Details

#clientObject (readonly)

Interaction with searchd and indexer.



63
64
65
# File 'lib/dm-sphinx-adapter/sphinx_adapter.rb', line 63

def client
  @client
end

Instance Method Details

#create(resources) ⇒ Object

:nodoc:



65
66
67
# File 'lib/dm-sphinx-adapter/sphinx_adapter.rb', line 65

def create(resources) #:nodoc:
  true
end

#delete(query) ⇒ Object

:nodoc:



69
70
71
# File 'lib/dm-sphinx-adapter/sphinx_adapter.rb', line 69

def delete(query) #:nodoc:
  true
end

#read_many(query) ⇒ Object



73
74
75
# File 'lib/dm-sphinx-adapter/sphinx_adapter.rb', line 73

def read_many(query)
  read(query)
end

#read_one(query) ⇒ Object



77
78
79
# File 'lib/dm-sphinx-adapter/sphinx_adapter.rb', line 77

def read_one(query)
  read(query).first
end