lib/esse/search/query.rb in esse-0.2.3 vs lib/esse/search/query.rb in esse-0.2.4
- old
+ new
@@ -1,19 +1,25 @@
# frozen_string_literal: true
+require_relative 'query/dsl'
module Esse
module Search
class Query
+ include DSL
attr_reader :transport, :definition
# @param transport [Esse::Transport] The client proxy to use for the query
# @param indices [<Array<Esse::Index, String>] The class of the index to search or the index name
# @param definition [Hash] The options to pass to the search.
def initialize(transport, *indices, suffix: nil, **definition, &_block)
@transport = transport
@definition = definition
- @definition[:index] = indices.map do |index|
+ @definition[:index] = self.class.normalize_indices(*indices, suffix: suffix) if indices.size > 0
+ end
+
+ def self.normalize_indices(*indices, suffix: nil)
+ indices.map do |index|
if index.is_a?(Class) && index < Esse::Index
index.index_name(suffix: suffix)
elsif index.is_a?(String) || index.is_a?(Symbol)
[index, suffix].compact.join('_')
else
@@ -89,17 +95,9 @@
resp
end
def reset!
@response = nil
- end
-
- def raw_limit_value
- definition.dig(:body, :size) || definition.dig(:body, 'size') || definition.dig(:size) || definition.dig('size')
- end
-
- def raw_offset_value
- definition.dig(:body, :from) || definition.dig(:body, 'from') || definition.dig(:from) || definition.dig('from')
end
end
end
end