Class: Noiseless::MultiSearchResponse

Inherits:
Response::Base show all
Defined in:
lib/noiseless/multi_search.rb

Overview

Multi-search response class

Instance Method Summary collapse

Methods inherited from Response::Base

#aggregations, #count, #each_with_index, #empty?, #hits, #include_pagination_info, #length, #response, #result, #results, #suggestions, #took, #total, #total_count

Methods included from Pagination::ResponsePagination

#current_page, #first_page?, #last_page?, #limit_value, #next_page, #offset_value, #out_of_range?, #pagination_metadata, #prev_page, #total_pages

Constructor Details

#initialize(raw_response, models, indexes) ⇒ MultiSearchResponse

Returns a new instance of MultiSearchResponse.



147
148
149
150
151
152
# File 'lib/noiseless/multi_search.rb', line 147

def initialize(raw_response, models, indexes)
  super(raw_response)
  @models = models
  @indexes = indexes
  @results_by_model = nil
end

Instance Method Details

#eachObject



154
155
156
157
158
# File 'lib/noiseless/multi_search.rb', line 154

def each(&)
  return enum_for(__method__) unless block_given?

  hits.each(&)
end

#each_model_resultObject



169
170
171
172
173
# File 'lib/noiseless/multi_search.rb', line 169

def each_model_result(&)
  return enum_for(__method__) unless block_given?

  results_by_model.each(&)
end

#model_countsObject



175
176
177
# File 'lib/noiseless/multi_search.rb', line 175

def model_counts
  results_by_model.transform_values(&:size)
end

#records_by_modelObject



179
180
181
# File 'lib/noiseless/multi_search.rb', line 179

def records_by_model
  @records_by_model ||= load_records_by_model
end

#records_for_model(model_class) ⇒ Object



183
184
185
186
# File 'lib/noiseless/multi_search.rb', line 183

def records_for_model(model_class)
  model_key = model_class.name.to_sym
  records_by_model[model_key] || []
end

#results_by_modelObject



160
161
162
# File 'lib/noiseless/multi_search.rb', line 160

def results_by_model
  @results_by_model ||= group_results_by_model
end

#results_for_model(model_class) ⇒ Object



164
165
166
167
# File 'lib/noiseless/multi_search.rb', line 164

def results_for_model(model_class)
  model_key = model_class.name.to_sym
  results_by_model[model_key] || []
end