Sha256: 04efe0b7bb13ddcdca6e5c55e2e5621887e6d97672bc209dc0ad10da71a633a2

Contents?: true

Size: 952 Bytes

Versions: 45

Compression:

Stored size: 952 Bytes

Contents

module Searchkick
  class MultiSearch
    attr_reader :queries

    def initialize(queries)
      @queries = queries
    end

    def perform
      if queries.any?
        perform_search(queries)
      end
    end

    private

    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

    def client
      Searchkick.client
    end
  end
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
searchkick-5.4.0 lib/searchkick/multi_search.rb
searchkick-5.3.1 lib/searchkick/multi_search.rb
searchkick-5.3.0 lib/searchkick/multi_search.rb
searchkick-5.2.4 lib/searchkick/multi_search.rb
searchkick-5.2.3 lib/searchkick/multi_search.rb
searchkick-5.2.2 lib/searchkick/multi_search.rb
searchkick-5.2.1 lib/searchkick/multi_search.rb
searchkick-5.2.0 lib/searchkick/multi_search.rb
searchkick-5.1.2 lib/searchkick/multi_search.rb
searchkick-5.1.1 lib/searchkick/multi_search.rb
searchkick-5.1.0 lib/searchkick/multi_search.rb
searchkick-5.0.5 lib/searchkick/multi_search.rb
searchkick-5.0.4 lib/searchkick/multi_search.rb
searchkick-5.0.3 lib/searchkick/multi_search.rb
searchkick-5.0.2 lib/searchkick/multi_search.rb
searchkick-5.0.1 lib/searchkick/multi_search.rb
searchkick-5.0.0 lib/searchkick/multi_search.rb
searchkick-4.6.3 lib/searchkick/multi_search.rb
searchkick-4.6.2 lib/searchkick/multi_search.rb
searchkick-4.6.1 lib/searchkick/multi_search.rb