class Searchkick::MultiSearch
Attributes
queries[R]
Public Class Methods
new(queries)
click to toggle source
# File lib/searchkick/multi_search.rb, line 5 def initialize(queries) @queries = queries end
Public Instance Methods
perform()
click to toggle source
# File lib/searchkick/multi_search.rb, line 9 def perform if queries.any? perform_search(queries) end end
Private Instance Methods
client()
click to toggle source
# File lib/searchkick/multi_search.rb, line 37 def client Searchkick.client end
perform_search(search_queries, perform_retry: true)
click to toggle source
# File lib/searchkick/multi_search.rb, line 17 def perform_search(search_queries, perform_retry: true) responses = client.msearch(body: search_queries.flat_map { |q| [q.params.except(:body), q.body] })["responses"] retry_queries = [] search_queries.each_with_index do |query, i| if perform_retry && query.retry_misspellings?(responses[i]) query.send(:prepare) # okay, since we don't want to expose this method outside Searchkick retry_queries << query else query.handle_response(responses[i]) end end if retry_queries.any? perform_search(retry_queries, perform_retry: false) end search_queries end