Class: Riddle::Controller
- Inherits:
-
Object
- Object
- Riddle::Controller
- Defined in:
- lib/riddle/controller.rb
Constant Summary collapse
- DEFAULT_MERGE_OPTIONS =
{:filters => {}}.freeze
Instance Attribute Summary collapse
-
#bin_path ⇒ Object
Returns the value of attribute bin_path.
-
#indexer_binary_name ⇒ Object
Returns the value of attribute indexer_binary_name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#searchd_binary_name ⇒ Object
Returns the value of attribute searchd_binary_name.
Instance Method Summary collapse
- #index(*indices) ⇒ Object
-
#initialize(configuration, path) ⇒ Controller
constructor
A new instance of Controller.
- #merge(destination, source, options = {}) ⇒ Object
- #pid ⇒ Object
- #rotate ⇒ Object
- #running? ⇒ Boolean
- #sphinx_version ⇒ Object
- #start(options = {}) ⇒ Object
- #stop(options = {}) ⇒ Object
Constructor Details
#initialize(configuration, path) ⇒ Controller
Returns a new instance of Controller.
11 12 13 14 15 16 17 18 |
# File 'lib/riddle/controller.rb', line 11 def initialize(configuration, path) @configuration = configuration @path = path @bin_path = '' @searchd_binary_name = 'searchd' @indexer_binary_name = 'indexer' end |
Instance Attribute Details
#bin_path ⇒ Object
Returns the value of attribute bin_path.
9 10 11 |
# File 'lib/riddle/controller.rb', line 9 def bin_path @bin_path end |
#indexer_binary_name ⇒ Object
Returns the value of attribute indexer_binary_name.
9 10 11 |
# File 'lib/riddle/controller.rb', line 9 def indexer_binary_name @indexer_binary_name end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/riddle/controller.rb', line 9 def path @path end |
#searchd_binary_name ⇒ Object
Returns the value of attribute searchd_binary_name.
9 10 11 |
# File 'lib/riddle/controller.rb', line 9 def searchd_binary_name @searchd_binary_name end |
Instance Method Details
#index(*indices) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/riddle/controller.rb', line 26 def index(*indices) = indices.last.is_a?(Hash) ? indices.pop : {} indices << '--all' if indices.empty? command = "#{indexer} --config \"#{@path}\" #{indices.join(' ')}" command = "#{command} --rotate" if running? Riddle::ExecuteCommand.call command, [:verbose] end |
#merge(destination, source, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/riddle/controller.rb', line 36 def merge(destination, source, = {}) = DEFAULT_MERGE_OPTIONS.merge command = "#{indexer} --config \"#{@path}\"".dup command << " --merge #{destination} #{source}" [:filters].each do |attribute, value| value = value..value unless value.is_a?(Range) command << " --merge-dst-range #{attribute} #{value.min} #{value.max}" end command << " --rotate" if running? Riddle::ExecuteCommand.call command, [:verbose] end |
#pid ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/riddle/controller.rb', line 76 def pid if File.exist?(configuration.searchd.pid_file) File.read(configuration.searchd.pid_file)[/\d+/] else nil end end |
#rotate ⇒ Object
84 85 86 |
# File 'lib/riddle/controller.rb', line 84 def rotate pid && Process.kill(:HUP, pid.to_i) end |
#running? ⇒ Boolean
88 89 90 91 92 |
# File 'lib/riddle/controller.rb', line 88 def running? !!pid && !!Process.kill(0, pid.to_i) rescue false end |
#sphinx_version ⇒ Object
20 21 22 23 24 |
# File 'lib/riddle/controller.rb', line 20 def sphinx_version `#{indexer} 2>&1`[/(Sphinx|Manticore) (\d+\.\d+(\.\d+|(?:-dev|(\-id64)?\-beta)))/, 2] rescue nil end |
#start(options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/riddle/controller.rb', line 50 def start( = {}) return if running? check_for_configuration_file command = "#{searchd} --pidfile --config \"#{@path}\"" command = "#{command} --nodetach" if [:nodetach] exec(command) if [:nodetach] # Code does not get here if nodetach is true. Riddle::ExecuteCommand.call command, [:verbose] end |
#stop(options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/riddle/controller.rb', line 63 def stop( = {}) return true unless running? check_for_configuration_file stop_flag = 'stopwait' stop_flag = 'stop' if Riddle.loaded_version.split('.').first == '0' command = %(#{searchd} --pidfile --config "#{@path}" --#{stop_flag}) result = Riddle::ExecuteCommand.call command, [:verbose] result.successful = !running? result end |