Class: XMLPipe2::DeltaIndexer

Inherits:
Object
  • Object
show all
Defined in:
lib/xml_pipe2/delta_indexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ DeltaIndexer

Returns a new instance of DeltaIndexer.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/xml_pipe2/delta_indexer.rb', line 5

def initialize instance
  @instance = instance

  @xml_stream = Tempfile.new('xml_stream.xml')
  @xml_stream.write(instance.xml_stream)
  @xml_stream.close

  @sphinx_conf = Tempfile.new('sphinx.conf')
  xml_stream_path = @xml_stream.path
  @sphinx_conf.write(ERB.new(instance.class.sphinx_conf).result(binding))
  @sphinx_conf.close
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



18
19
20
# File 'lib/xml_pipe2/delta_indexer.rb', line 18

def instance
  @instance
end

#sphinx_confObject (readonly)

Returns the value of attribute sphinx_conf.



18
19
20
# File 'lib/xml_pipe2/delta_indexer.rb', line 18

def sphinx_conf
  @sphinx_conf
end

#xml_streamObject (readonly)

Returns the value of attribute xml_stream.



18
19
20
# File 'lib/xml_pipe2/delta_indexer.rb', line 18

def xml_stream
  @xml_stream
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
# File 'lib/xml_pipe2/delta_indexer.rb', line 20

def run
  config = '-c ' + sphinx_conf.path
  index = instance.class.to_s.downcase
  system("$(which indexer) #{config} #{index}_delta && $(which indexer) #{config} --merge #{index} #{index}_delta --rotate")
  sphinx_conf.unlink
  xml_stream.unlink
end