Sha256: c3723ffe79224f03a9e84f1bf23d873d07907d2efa7075c91cfe06ff0e93b22f
Contents?: true
Size: 1.15 KB
Versions: 13
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true module Esse class Index module ClassMethods # @param query_or_payload [String,Hash] The search request definition or query in the Lucene query string syntax # @param kwargs [Hash] The options to pass to the search. def search(*args, &block) kwargs = extract_search_options!(args) cluster.search(self, **kwargs, &block) end private def extract_search_options!(args) query_or_payload = args.shift kwargs = args.last.is_a?(Hash) ? args.pop : {} if query_or_payload.respond_to?(:to_hash) && (hash = query_or_payload.to_hash) && (hash.key?(:body) || hash.key?('body') || hash.key?(:q) || hash.key?('q')) kwargs.merge!(hash.transform_keys(&:to_sym)) elsif query_or_payload.respond_to?(:to_hash) kwargs[:body] = query_or_payload.to_hash elsif query_or_payload.is_a?(String) && query_or_payload =~ /^\s*{/ kwargs[:body] = MultiJson.load(query_or_payload) elsif query_or_payload.is_a?(String) kwargs[:q] = query_or_payload end kwargs end end extend ClassMethods end end
Version data entries
13 entries across 13 versions & 1 rubygems