Class: Daedal::Queries::RangeQuery
- 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
-
#initialize(options = {}) ⇒ RangeQuery
constructor
A new instance of RangeQuery.
- #to_hash ⇒ Object
Methods inherited from Query
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(={}) super # 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_hash ⇒ Object
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 |