Class: ThinkingSphinx::RakeInterface

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) clear



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

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

- (Object) configure



11
12
13
14
# File 'lib/thinking_sphinx/rake_interface.rb', line 11

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

- (Object) generate



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/thinking_sphinx/rake_interface.rb', line 16

def generate
  configuration.preload_indices
  configuration.render

  FileUtils.mkdir_p configuration.indices_location

  configuration.indices.each do |index|
    next unless index.is_a?(ThinkingSphinx::RealTime::Index)

    puts "Generating index files for #{index.name}"
    transcriber = ThinkingSphinx::RealTime::Transcriber.new index
    Dir["#{index.path}*"].each { |file| FileUtils.rm file }

    index.model.find_each do |instance|
      transcriber.copy instance
      print "."
    end
    print "\n"

    controller.rotate
  end
end

- (Object) index(reconfigure = true)



39
40
41
42
43
44
# File 'lib/thinking_sphinx/rake_interface.rb', line 39

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

- (Object) start

Raises:

  • (RuntimeError)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/thinking_sphinx/rake_interface.rb', line 46

def start
  raise RuntimeError, 'searchd is already running' if controller.running?

  FileUtils.mkdir_p configuration.indices_location
  controller.start

  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

- (Object) stop



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/thinking_sphinx/rake_interface.rb', line 59

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