Class: DataMapper::SphinxConfig

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

Instance Method Summary collapse

Constructor Details

#initialize(uri_or_options = {}) ⇒ SphinxConfig

Read a sphinx configuration file.

This class just gives you access to handy searchd {} configuration options. It does not validate your configuration file beyond basic syntax checking.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dm-sphinx-adapter/sphinx_config.rb', line 15

def initialize(uri_or_options = {})
  @config  = []
  @searchd = {
    'address'         => '0.0.0.0',
    'log'             => 'searchd.log',
    'max_children'    => 0,
    'max_matches'     => 1000,
    'pid_file'        => nil,
    'port'            => 3312,
    'preopen_indexes' => 0,
    'query_log'       => '',
    'read_timeout'    => 5,
    'seamless_rotate' => 1,
    'unlink_old'      => 1
  }

  path = case uri_or_options
    when Addressable::URI, DataObjects::URI then uri_or_options.path
    when Hash                               then uri_or_options[:config] || uri_or_options[:database]
    when Pathname                           then uri_or_options
    when String                             then DataObjects::URI.parse(uri_or_options).path
  end
  parse('' + path.to_s) # Force stringy since Pathname#to_s is broken IMO.
end

Instance Method Details

#addressObject

Searchd address.



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

def address
  searchd['address']
end

#configString

Configuration file full path name.

Returns:

  • (String)


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

def config
  @config
end

#indexer_bin(use_config = true) ⇒ Object

Indexer binary full path name and config argument.



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

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

#logObject

Searchd log file.



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

def log
  searchd['log']
end

#pid_fileObject

Searchd pid_file.



78
79
80
# File 'lib/dm-sphinx-adapter/sphinx_config.rb', line 78

def pid_file
  searchd['pid_file'] or raise "Mandatory pid_file option missing from searchd configuration."
end

#portObject

Searchd port.



72
73
74
# File 'lib/dm-sphinx-adapter/sphinx_config.rb', line 72

def port
  searchd['port']
end

#searchdObject

Searchd configuration options.



92
93
94
# File 'lib/dm-sphinx-adapter/sphinx_config.rb', line 92

def searchd
  @searchd
end

#searchd_bin(use_config = true) ⇒ Object

Searchd binardy full path name and config argument.



58
59
60
61
62
# File 'lib/dm-sphinx-adapter/sphinx_config.rb', line 58

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