Class: Esse::Search::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/esse/search/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, raw_response, **options) ⇒ Response

Returns a new instance of Response.

Parameters:

  • query (Esse::Search::Query)

    The search query

  • raw_response (Hash)

    The raw response from Elasticsearch

  • options (Hash)

    The options passed to the search



15
16
17
18
19
# File 'lib/esse/search/response.rb', line 15

def initialize(query, raw_response, **options)
  @query = query
  @raw_response = raw_response
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/esse/search/response.rb', line 10

def options
  @options
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'lib/esse/search/response.rb', line 10

def query
  @query
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



10
11
12
# File 'lib/esse/search/response.rb', line 10

def raw_response
  @raw_response
end

Instance Method Details

#aggregationsObject



25
26
27
# File 'lib/esse/search/response.rb', line 25

def aggregations
  raw_response['aggregations']
end

#hitsObject



33
34
35
# File 'lib/esse/search/response.rb', line 33

def hits
  raw_response.dig('hits', 'hits') || []
end

#shardsObject



21
22
23
# File 'lib/esse/search/response.rb', line 21

def shards
  raw_response['_shards']
end

#suggestionsObject



29
30
31
# File 'lib/esse/search/response.rb', line 29

def suggestions
  raw_response['suggest']
end

#totalObject



37
38
39
40
41
42
43
# File 'lib/esse/search/response.rb', line 37

def total
  if raw_response.dig('hits', 'total').respond_to?(:keys)
    raw_response.dig('hits', 'total', 'value')
  else
    raw_response.dig('hits', 'total')
  end.to_i
end