Class: DataMapper::Adapters::Sphinx::Client
- Inherits:
-
Object
- Object
- DataMapper::Adapters::Sphinx::Client
- Defined in:
- lib/dm-sphinx-adapter/client.rb
Overview
Client wrapper for Riddle::Client.
-
Simple interface to
searchd
andindexer
. -
Can read
searchd
configuration options from your sphinx configuration file. -
Managed
searchd
usingdaemon_controller
for on demand daemon control in development.
Direct Known Subclasses
Instance Method Summary collapse
-
#index(indexes = nil) ⇒ Object
Index one or more indexes.
-
#initialize(uri_or_options = {}) ⇒ Client
constructor
Parameters uri_or_options<URI, DataObject::URI, Addressable::URI, String, Hash, Pathname>:: DataMapper uri or options hash.
-
#search(query, indexes = '*', options = {}) ⇒ Object
Search one or more indexes.
Constructor Details
Instance Method Details
#index(indexes = nil) ⇒ Object
Index one or more indexes.
Parameters
- indexes<Array, String>
-
Indexes to index (and rotate). Defaults to –all if indexes is
nil
or ‘*’.
47 48 49 50 51 52 53 54 |
# File 'lib/dm-sphinx-adapter/client.rb', line 47 def index(indexes = nil) indexes = indexes.join(' ') if indexes.kind_of?(Array) command = @config.indexer_bin command << " --rotate" if running? command << ((indexes.nil? || indexes == '*') ? ' --all' : " #{indexes.to_s}") warn "Sphinx: Indexer #{$1}" if `#{command}` =~ /(?:error|fatal|warning):?\s*([^\n]+)/i end |
#search(query, indexes = '*', options = {}) ⇒ Object
Search one or more indexes.
See
-
Riddle::Client
Parameters
- query<String>
-
A sphinx query string.
- indexes<Array, String>
-
Indexes to search. Default is ‘*’ all.
- options<Hash>
-
Any attributes supported by the Riddle::Client.
Returns
- Hash
-
Riddle::Client#query response struct.
35 36 37 38 39 40 41 |
# File 'lib/dm-sphinx-adapter/client.rb', line 35 def search(query, indexes = '*', = {}) indexes = indexes.join(' ') if indexes.kind_of?(Array) client = Riddle::Client.new(@config.address, @config.port) .each{|k, v| client.method("#{k}=".to_sym).call(v) if client.respond_to?("#{k}=".to_sym)} client.query(query, indexes.to_s) end |