Class: DataMapper::Adapters::Sphinx::Config

Inherits:
Object
  • Object
show all
Includes:
Extlib::Assertions
Defined in:
lib/dm-sphinx-adapter/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri_or_options = {}) ⇒ Config

Sphinx configuration options.

This class just gives you access to handy searchd {} configuration options. If a sphinx configuration file is passed and can be parsed searchd options will be set straight from the file.

Notes

Option precedence is:

  • The options hash.

  • The configuration file.

  • Sphinx defaults.

See

www.sphinxsearch.com/doc.html#confgroup-searchd

Parameters

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

DataMapper uri or options hash.



32
33
34
35
36
37
38
39
40
41
# File 'lib/dm-sphinx-adapter/config.rb', line 32

def initialize(uri_or_options = {})
  assert_kind_of 'uri_or_options', uri_or_options, Addressable::URI, DataObjects::URI, Hash, String, Pathname

  options   = normalize_options(uri_or_options)
  config    = parse_config("#{options[:path]}") # Pathname#to_s is broken?
  @address  = options[:host]     || config['address']  || '0.0.0.0'
  @port     = options[:port]     || config['port']     || 3312
  @log      = options[:log]      || config['log']      || 'searchd.log'
  @pid_file = options[:pid_file] || config['pid_file']
end

Instance Attribute Details

#addressObject (readonly)

Configuration option.



13
14
15
# File 'lib/dm-sphinx-adapter/config.rb', line 13

def address
  @address
end

#configObject (readonly)

Configuration option.



13
14
15
# File 'lib/dm-sphinx-adapter/config.rb', line 13

def config
  @config
end

#logObject (readonly)

Configuration option.



13
14
15
# File 'lib/dm-sphinx-adapter/config.rb', line 13

def log
  @log
end

#portObject (readonly)

Configuration option.



13
14
15
# File 'lib/dm-sphinx-adapter/config.rb', line 13

def port
  @port
end

Instance Method Details

#indexer_bin(use_config = true) ⇒ Object

Indexer binary full path name and config argument.

Parameters

use_config<Boolean>

Return --config path/to/config.conf as part of string. Default true.

Returns

String



50
51
52
53
54
# File 'lib/dm-sphinx-adapter/config.rb', line 50

def indexer_bin(use_config = true)
  path = 'indexer' # TODO: Real.
  path << " --config #{config}" if config
  path
end

#pid_fileObject

Full path to pid_file.

Raises

RuntimeError

If a pid file was not read or set. pid_file is a mandatory searchd option in a sphinx

configuration file.


74
75
76
# File 'lib/dm-sphinx-adapter/config.rb', line 74

def pid_file
  @pid_file or raise "Mandatory pid_file option missing from searchd configuration."
end

#searchd_bin(use_config = true) ⇒ Object

Searchd binary full path name and config argument.

Parameters

use_config<Boolean>

Return --config path/to/config.conf as part of string. Default true.

Returns

String



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

def searchd_bin(use_config = true)
  path = 'searchd' # TODO: Real.
  path << " --config #{config}" if config
  path
end