Module: Caoutsearch::Search::Response
- Included in:
- Base
- Defined in:
- lib/caoutsearch/search/response.rb
Instance Method Summary collapse
- #aggregations ⇒ Object
- #each(&block) ⇒ Object
- #hits ⇒ Object
- #ids ⇒ Object
- #load ⇒ Object
- #loaded? ⇒ Boolean
- #max_score ⇒ Object
- #perform_search_query(query) ⇒ Object
- #raw_response ⇒ Object
- #response ⇒ Object
- #shards ⇒ Object
- #suggestions ⇒ Object
- #timed_out ⇒ Object
- #took ⇒ Object
- #total ⇒ Object
- #total_count ⇒ Object
- #total_pages ⇒ Object
Instance Method Details
#aggregations ⇒ Object
70 71 72 |
# File 'lib/caoutsearch/search/response.rb', line 70 def aggregations @aggregations ||= Caoutsearch::Response::Aggregations.new(response.aggregations, self) end |
#each(&block) ⇒ Object
78 79 80 81 82 |
# File 'lib/caoutsearch/search/response.rb', line 78 def each(&block) return to_enum(:each) { hits.size } unless block hits.each(&block) end |
#hits ⇒ Object
42 43 44 |
# File 'lib/caoutsearch/search/response.rb', line 42 def hits response.dig("hits", "hits") end |
#ids ⇒ Object
66 67 68 |
# File 'lib/caoutsearch/search/response.rb', line 66 def ids hits.map { |hit| hit["_id"] } end |
#load ⇒ Object
9 10 11 12 13 14 |
# File 'lib/caoutsearch/search/response.rb', line 9 def load @raw_response = perform_search_query(build.to_h) @response = Caoutsearch::Response::Response.new(@raw_response) @loaded = true self end |
#loaded? ⇒ Boolean
16 17 18 |
# File 'lib/caoutsearch/search/response.rb', line 16 def loaded? @loaded end |
#max_score ⇒ Object
46 47 48 |
# File 'lib/caoutsearch/search/response.rb', line 46 def max_score response.dig("hits", "max_score") end |
#perform_search_query(query) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/caoutsearch/search/response.rb', line 84 def perform_search_query(query) request_payload = { index: index_name, body: query } instrument(:search) do |event_payload| event_payload[:request] = request_payload event_payload[:response] = client.search(request_payload) end end |
#raw_response ⇒ Object
25 26 27 28 |
# File 'lib/caoutsearch/search/response.rb', line 25 def raw_response load unless loaded? @raw_response end |
#response ⇒ Object
20 21 22 23 |
# File 'lib/caoutsearch/search/response.rb', line 20 def response load unless loaded? @response end |
#shards ⇒ Object
38 39 40 |
# File 'lib/caoutsearch/search/response.rb', line 38 def shards response["_shards"] end |
#suggestions ⇒ Object
74 75 76 |
# File 'lib/caoutsearch/search/response.rb', line 74 def suggestions @suggestions ||= Caoutsearch::Response::Suggestions.new(response.suggest) end |
#timed_out ⇒ Object
34 35 36 |
# File 'lib/caoutsearch/search/response.rb', line 34 def timed_out response["timed_out"] end |
#took ⇒ Object
30 31 32 |
# File 'lib/caoutsearch/search/response.rb', line 30 def took response["took"] end |
#total ⇒ Object
50 51 52 |
# File 'lib/caoutsearch/search/response.rb', line 50 def total response.dig("hits", "total") end |
#total_count ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/caoutsearch/search/response.rb', line 54 def total_count if !@track_total_hits && (!loaded? || response.dig("hits", "total", "relation") == "gte") @total_count ||= spawn.track_total_hits!(true).source!(false).limit!(0).total_count else response.dig("hits", "total", "value") end end |
#total_pages ⇒ Object
62 63 64 |
# File 'lib/caoutsearch/search/response.rb', line 62 def total_pages (total_count.to_f / current_limit).ceil end |