module Elastic::Shims::Concerns::HitPicker

Public Instance Methods

handle_result(_raw, _formatter) click to toggle source
Calls superclass method
# File lib/elastic/shims/concerns/hit_picker.rb, line 8
def handle_result(_raw, _formatter)
  result = super

  case result
  when Elastic::Results::Root
    transform_collection(result)
  when Elastic::Results::GroupedResult
    result.map_to_group { |c| transform_collection(c) }
  else
    raise "unable to pick from result of type #{result.class}"
  end
end
render(_options = {}) click to toggle source
Calls superclass method
# File lib/elastic/shims/concerns/hit_picker.rb, line 3
def render(_options = {})
  set_hits_source unless required_source_fields.nil?
  super
end

Private Instance Methods

pick_from_hit(_hit) click to toggle source
# File lib/elastic/shims/concerns/hit_picker.rb, line 33
def pick_from_hit(_hit)
  raise NotImplementedError, 'pick_from_hit not implemented'
end
required_source_fields() click to toggle source
# File lib/elastic/shims/concerns/hit_picker.rb, line 37
def required_source_fields
  nil
end
set_hits_source() click to toggle source
# File lib/elastic/shims/concerns/hit_picker.rb, line 23
def set_hits_source
  child.pick(Elastic::Nodes::Concerns::HitProvider) do |node|
    node.source = required_source_fields
  end
end
transform_collection(_collection) click to toggle source
# File lib/elastic/shims/concerns/hit_picker.rb, line 29
def transform_collection(_collection)
  _collection.map_with_score { |h| pick_from_hit(h) }
end