Class: ES::Index::SearchResponse

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

Overview

{

     "took" => 0,
"timed_out" => false,
  "_shards" => {
           "total" => 5,
      "successful" => 5,
          "failed" => 0
  },
     "hits" => {
            "total" => 2468,
        "max_score" => 1.0,
             "hits" => [
            [0] {
                 "_index" => "services",
                  "_type" => "service",
                    "_id" => "b86ac976-5c5b-11e3-9470-cc5bbc629773",
                 "_score" => 1.0,
                "_source" => {
                            "name" => "...",
                            "guid" => "b86ac976-5c5b-11e3-9470-cc5bbc629773",
                     "description" => nil,
                    "account_guid" => "77c57a7f-6ff3-4918-8f61-ef5ae5a04e18",
                       "user_guid" => "3cc66723-f788-40d7-8583-bfa09cec5623",
                          "domain" => nil,
                       "is_public" => false
                }
            }
        ]
    }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, model) ⇒ SearchResponse

Returns a new instance of SearchResponse.



40
41
42
43
44
# File 'lib/es/index/search_response.rb', line 40

def initialize(response, model)
  @raw_response = HashResponse.new(response)
  @model = model
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



78
79
80
# File 'lib/es/index/search_response.rb', line 78

def method_missing(method, *args, &block)
  @raw_response.send(method, *args, &block)
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



38
39
40
# File 'lib/es/index/search_response.rb', line 38

def model
  @model
end

#raw_responseObject

Returns the value of attribute raw_response.



37
38
39
# File 'lib/es/index/search_response.rb', line 37

def raw_response
  @raw_response
end

Instance Method Details

#hitsObject



46
47
48
# File 'lib/es/index/search_response.rb', line 46

def hits
  HashResponse.new(@raw_response.hits)
end

#max_scoreObject



54
55
56
# File 'lib/es/index/search_response.rb', line 54

def max_score
  hits.max_score
end

#modelsObject



62
63
64
# File 'lib/es/index/search_response.rb', line 62

def models
  @model.es_results_to_models.call(results)
end

#resultsObject



58
59
60
# File 'lib/es/index/search_response.rb', line 58

def results
  hits.hits
end

#shardsObject



74
75
76
# File 'lib/es/index/search_response.rb', line 74

def shards
  @raw_response._shards
end

#timed_outObject



70
71
72
# File 'lib/es/index/search_response.rb', line 70

def timed_out
  @raw_response.timed_out
end

#tookObject



66
67
68
# File 'lib/es/index/search_response.rb', line 66

def took
  @raw_response.took
end

#totalObject



50
51
52
# File 'lib/es/index/search_response.rb', line 50

def total
  hits.total
end