Class: Cadet::CadetIndex::Index
- Inherits:
-
Object
- Object
- Cadet::CadetIndex::Index
- Defined in:
- lib/cadet/cadet_index/index.rb
Instance Method Summary collapse
- #add(node, prop, value) ⇒ Object
- #flush ⇒ Object
- #get(property, value) ⇒ Object
-
#initialize(lucene_index, name, type) ⇒ Index
constructor
A new instance of Index.
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 |