Class: Elastic::Results::ScoredCollection

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elastic/results/scored_collection.rb

Direct Known Subclasses

HitCollection

Instance Method Summary collapse

Methods inherited from Base

#as_value

Methods included from Support::Traversable

#pick_nodes

Constructor Details

#initialize(_collection) ⇒ ScoredCollection

Returns a new instance of ScoredCollection.



5
6
7
# File 'lib/elastic/results/scored_collection.rb', line 5

def initialize(_collection)
  @collection = _collection
end

Instance Method Details

#[](_idx) ⇒ Object



13
14
15
# File 'lib/elastic/results/scored_collection.rb', line 13

def [](_idx)
  @collection[_idx].try(:data)
end

#countObject



9
10
11
# File 'lib/elastic/results/scored_collection.rb', line 9

def count
  @collection.count
end

#each(&_block) ⇒ Object



21
22
23
# File 'lib/elastic/results/scored_collection.rb', line 21

def each(&_block)
  @collection.map(&:data).each(&_block)
end

#each_with_score(&_block) ⇒ Object



25
26
27
# File 'lib/elastic/results/scored_collection.rb', line 25

def each_with_score(&_block)
  @collection.map { |sd| [sd.data, sd.score] }.each(&_block)
end

#lastObject



17
18
19
# File 'lib/elastic/results/scored_collection.rb', line 17

def last
  @collection.last.try(:data)
end

#map_with_score(&_block) ⇒ Object



29
30
31
32
33
# File 'lib/elastic/results/scored_collection.rb', line 29

def map_with_score(&_block)
  ScoredCollection.new(
    @collection.map { |sd| ScoredItem.new(_block.call(sd), sd.score) }.to_a
  )
end

#traverse(&_block) ⇒ Object



35
36
37
38
# File 'lib/elastic/results/scored_collection.rb', line 35

def traverse(&_block)
  super
  @collection.each { |sd| sd.traverse(&_block) }
end