Class: ThinkingSphinx::RakeInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/rake_interface.rb

Instance Method Summary collapse

Instance Method Details

#clear_allObject



2
3
4
5
6
7
8
9
# File 'lib/thinking_sphinx/rake_interface.rb', line 2

def clear_all
  [
    configuration.indices_location,
    configuration.searchd.binlog_path
  ].each do |path|
    FileUtils.rm_r(path) if File.exists?(path)
  end
end

#clear_real_timeObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/thinking_sphinx/rake_interface.rb', line 11

def clear_real_time
  indices = configuration.indices.select { |index| index.type == 'rt' }
  indices.each do |index|
    index.render
    Dir["#{index.path}.*"].each { |path| FileUtils.rm path }
  end

  path = configuration.searchd.binlog_path
  FileUtils.rm_r(path) if File.exists?(path)
end

#configureObject



22
23
24
25
# File 'lib/thinking_sphinx/rake_interface.rb', line 22

def configure
  puts "Generating configuration to #{configuration.configuration_file}"
  configuration.render_to_file
end

#generateObject



27
28
29
30
31
32
# File 'lib/thinking_sphinx/rake_interface.rb', line 27

def generate
  indices = configuration.indices.select { |index| index.type == 'rt' }
  indices.each do |index|
    ThinkingSphinx::RealTime::Populator.populate index
  end
end

#index(reconfigure = true, verbose = true) ⇒ Object



34
35
36
37
38
39
# File 'lib/thinking_sphinx/rake_interface.rb', line 34

def index(reconfigure = true, verbose = true)
  configure if reconfigure
  FileUtils.mkdir_p configuration.indices_location
  ThinkingSphinx.before_index_hooks.each { |hook| hook.call }
  controller.index :verbose => verbose
end

#prepareObject



41
42
43
44
45
46
# File 'lib/thinking_sphinx/rake_interface.rb', line 41

def prepare
  configuration.preload_indices
  configuration.render

  FileUtils.mkdir_p configuration.indices_location
end

#start(options = {}) ⇒ Object

Raises:

  • (RuntimeError)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/thinking_sphinx/rake_interface.rb', line 48

def start(options={})
  raise RuntimeError, 'searchd is already running' if controller.running?

  FileUtils.mkdir_p configuration.indices_location

  if options[:nodetach]
    unless pid = fork
      controller.start(options)
    end
    Signal.trap('TERM') { Process.kill(:TERM, pid); }
    Signal.trap('INT')  { Process.kill(:TERM, pid); }
    Process.wait(pid)
  else
    controller.start(options)
    if controller.running?
      puts "Started searchd successfully (pid: #{controller.pid})."
    else
      puts "Failed to start searchd. Check the log files for more information."
    end
  end
end

#statusObject



70
71
72
73
74
75
76
# File 'lib/thinking_sphinx/rake_interface.rb', line 70

def status
  if controller.running?
    puts "The Sphinx daemon searchd is currently running."
  else
    puts "The Sphinx daemon searchd is not currently running."
  end
end

#stopObject



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/thinking_sphinx/rake_interface.rb', line 78

def stop
  unless controller.running?
    puts 'searchd is not currently running.' and return
  end

  pid = controller.pid
  until controller.stop do
    sleep(0.5)
  end

  puts "Stopped searchd daemon (pid: #{pid})."
end