Class: Cadet::BatchInserter::CadetIndex::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/cadet/batch_inserter/cadet_index/index.rb

Instance Method Summary collapse

Constructor Details

#initialize(lucene_index, name) ⇒ Index

Returns a new instance of Index.



5
6
7
8
9
# File 'lib/cadet/batch_inserter/cadet_index/index.rb', line 5

def initialize(lucene_index, name)
  @name = name.to_sym
  @property_index = {}
  @lucene_index = lucene_index
end

Instance Method Details

#add(node, property, value) ⇒ Object



11
12
13
14
15
# File 'lib/cadet/batch_inserter/cadet_index/index.rb', line 11

def add(node, property, value)
  @property_index[property.to_sym] ||= {}
  @property_index[property.to_sym][value] ||= []
  @property_index[property.to_sym][value] << node
end

#flushObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cadet/batch_inserter/cadet_index/index.rb', line 22

def flush
  lucene_node_index = @lucene_index.nodeIndex(@name, {"type" => "exact"})

  @property_index.each do |property, propval_to_node_mappings|
    propval_to_node_mappings.each do |value, nodes|
      nodes.each do |node|
        lucene_node_index.add(node, {property.to_java_string => value})
      end
    end
  end
end

#get(property, value) ⇒ Object



17
18
19
20
# File 'lib/cadet/batch_inserter/cadet_index/index.rb', line 17

def get(property, value)
  @property_index[property.to_sym] ||= {}
  @property_index[property.to_sym][value] || []
end