Class: Daedal::Queries::RangeQuery

Inherits:
Query
  • Object
show all
Defined in:
lib/daedal/queries/range_query.rb

Constant Summary collapse

MINIMUM_ATTRIBUTES =

non required attributes, but at least one must be given

[:gte, :gt, :lte, :lt].sort

Instance Method Summary collapse

Methods inherited from Query

#to_json

Constructor Details

#initialize(options = {}) ⇒ RangeQuery

Returns a new instance of RangeQuery.



16
17
18
19
20
21
22
# File 'lib/daedal/queries/range_query.rb', line 16

def initialize(options={})
  super options

  # ensure at least one of the minimum attributes is provided
  raise "Must give at least one of the following: #{MINIMUM_ATTRIBUTES.join(', ')}" unless (attributes.reject { |k,v| v.nil? }.keys & MINIMUM_ATTRIBUTES).length > 0

end

Instance Method Details

#to_hashObject



24
25
26
27
28
29
# File 'lib/daedal/queries/range_query.rb', line 24

def to_hash
  inner_result = attributes.select { |k,v| MINIMUM_ATTRIBUTES.include?(k) && !v.nil? }
  inner_result.merge!(boost: boost) if boost

  {range: {field => inner_result} }
end