Class: DataMapper::Adapters::Sphinx::Adapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/dm-sphinx-adapter/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 hashes when queried. The DataMapper library dm-more however provides dm-is-searchable, a common interface to search one adapter and load documents from another. My preference is to use this adapter in tandem with dm-is-searchable.

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)

Alternatively supply a Hash:

DataMapper.setup(:search, {
  :adapter  => 'sphinx',       # required
  :host     => 'localhost',    # optional. Default: localhost
  :port     => 3312            # optional. Default: 3312
})

Instance Method Summary collapse

Constructor Details

#initialize(name, uri_or_options) ⇒ Adapter

See

  • DataMapper::Adapters::AbstractAdapter

Parameters

uri_or_options<URI, DataObject::URI, Addressable::URI, String, Hash, Pathname>

DataMapper uri or options hash.



38
39
40
41
# File 'lib/dm-sphinx-adapter/adapter.rb', line 38

def initialize(name, uri_or_options)
  super # Set up defaults.
  @options = normalize_options(uri_or_options)
end

Instance Method Details

#create(resources) ⇒ Object

:nodoc:



43
44
45
# File 'lib/dm-sphinx-adapter/adapter.rb', line 43

def create(resources) #:nodoc:
  0
end

#delete(query) ⇒ Object

:nodoc:



47
48
49
# File 'lib/dm-sphinx-adapter/adapter.rb', line 47

def delete(query) #:nodoc:
  0
end

#read_many(query) ⇒ Object

Query your Sphinx repository and return all matching documents.

Notes

These methods are public but normally called indirectly through DataMapper::Resource#get, DataMapper::Resource#first or DataMapper::Resource#all.

The document hashes returned are those from Riddle::Client.

Parameters

query<DataMapper::Query>

The query object.

Returns

Array<Hash>

An array of document hashes. [{:id => 1, ...}, {:id => 2, ...}]

Array<>

An empty array if no documents match.



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

def read_many(query)
  read(query)
end

#read_one(query) ⇒ Object

Query your Sphinx repository and return the first document matched.

Notes

These methods are public but normally called indirectly through DataMapper::Resource#get, DataMapper::Resource#first or DataMapper::Resource#all.

Parameters

query<DataMapper::Query>

The query object.

Returns

Hash

An document hash of the first document matched. {:id => 1, ...}

Nil

If no documents match.



83
84
85
# File 'lib/dm-sphinx-adapter/adapter.rb', line 83

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