Class: Cadet::CadetIndex::Index

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

Instance Method Summary collapse

Constructor Details

#initialize(lucene_index, name, type) ⇒ Index

Returns a new instance of Index.



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

def initialize(lucene_index, name, type)
  @name = name
  @type = type
  @index = {}
  @lucene_index = lucene_index
end

Instance Method Details

#add(node, prop, value) ⇒ Object



10
11
12
13
# File 'lib/cadet/cadet_index/index.rb', line 10

def add(node, prop, value)
  @index[prop] ||= {}
  @index[prop][value] = node
end

#flush ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/cadet/cadet_index/index.rb', line 18

def flush
  index = @lucene_index.nodeIndex @name, @type
  @index.each do |property, mappings|
    mappings.each do |value, node|
      index.add(node, {property => value})
    end
  end
end

#get(property, value) ⇒ Object



14
15
16
17
# File 'lib/cadet/cadet_index/index.rb', line 14

def get(property, value)
  @index[property] ||= {}
  [@index[property][value]]
end