Class: ElasticAdapter::Decoration::SearchResponse

Inherits:
Decorator
  • Object
show all
Defined in:
lib/elastic_adapter/decoration/search_response.rb

Overview

Used to decorate responses from the elasticsearch search api

Instance Attribute Summary collapse

Attributes inherited from Decorator

#original_object

Instance Method Summary collapse

Methods inherited from Decorator

#initialize, #object

Constructor Details

This class inherits a constructor from ElasticAdapter::Decoration::Decorator

Instance Attribute Details

#countInteger (readonly)

the total amount of search results

Returns:

  • (Integer)

    the current value of count


6
7
8
# File 'lib/elastic_adapter/decoration/search_response.rb', line 6

def count
  @count
end

Instance Method Details

#alter_object(hash) ⇒ Hash

Reduces the interface and assigns the @count variable

Parameters:

  • hash (Hash)

Returns:

  • (Hash)

13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/elastic_adapter/decoration/search_response.rb', line 13

def alter_object(hash)
  new_hash = {}
  new_hash[:count] = hash[:hits][:total]
  @count = new_hash[:count]
  new_hash[:hits] = []

  hash[:hits][:hits].each do |hit|
    new_hash[:hits] << HitDecorator.new(hit)
  end

  new_hash
end