Class: AWSCloudSearch::SearchResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_cloud_search/search_response.rb

Constant Summary collapse

FIELDS =

error is an undocumented field that occurs when an error is returned

[ :match_expr, :rank, :cpu_time_ms, :time_ms, :rid, :found, :start, :error, :messages, :facets ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ SearchResponse

Takes in the hash, representing the json object returned from a search request



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aws_cloud_search/search_response.rb', line 13

def initialize(response)
  @response = response

  FIELDS.each do |f|
    fs = f.to_s.gsub('_' , '-')
    if @response.has_key? 'info' and @response['info'][fs]
      val = @response['info'][fs]
    elsif @response.has_key? 'hits' and @response['hits'][fs]
      val = @response['hits'][fs]
    else
      val = @response[fs]
    end
    self.instance_variable_set "@#{f}", val unless val.nil?
  end

  @hits = @response['hits']['hit'] if @response.has_key? 'hits'
end

Instance Attribute Details

#hitsObject (readonly) Also known as: results

Returns the value of attribute hits.



4
5
6
# File 'lib/aws_cloud_search/search_response.rb', line 4

def hits
  @hits
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/aws_cloud_search/search_response.rb', line 3

def response
  @response
end

Instance Method Details

#result_sizeObject



31
32
33
# File 'lib/aws_cloud_search/search_response.rb', line 31

def result_size
  @hits ? @hits.size : 0
end