Class: Chewy::Query::Nodes::Range
- Defined in:
- lib/chewy/query/nodes/range.rb
Constant Summary collapse
- EXECUTION =
{ i: :index, index: :index, f: :fielddata, fielddata: :fielddata }.freeze
Instance Method Summary collapse
- #&(other) ⇒ Object
- #__name__ ⇒ Object
- #__options__ ⇒ Object
- #__render__ ⇒ Object
- #__state__ ⇒ Object
-
#initialize(name, *args) ⇒ Range
constructor
A new instance of Range.
Methods inherited from Expr
Methods inherited from Base
Constructor Details
#initialize(name, *args) ⇒ Range
Returns a new instance of Range.
12 13 14 15 16 17 18 19 |
# File 'lib/chewy/query/nodes/range.rb', line 12 def initialize(name, *args) @name = name.to_s = args. @range = .select { |k, _v| i[gt lt].include?(k) } @bounds = .select { |k, _v| i[left_closed right_closed].include?(k) } execution = EXECUTION[args.first.to_sym] if args.first [:execution] = execution if execution end |
Instance Method Details
#&(other) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chewy/query/nodes/range.rb', line 21 def &(other) if other.is_a?(self.class) && other.__name__ == @name state = __state__.merge(other.__state__) cache = other.[:cache] || [:cache] state[:cache] = cache unless cache.nil? execution = other.[:execution] || [:execution] state[:execution] = execution unless execution.nil? self.class.new(@name, state) else super end end |
#__name__ ⇒ Object
37 38 39 |
# File 'lib/chewy/query/nodes/range.rb', line 37 def __name__ @name end |
#__options__ ⇒ Object
45 46 47 |
# File 'lib/chewy/query/nodes/range.rb', line 45 def end |
#__render__ ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chewy/query/nodes/range.rb', line 49 def __render__ body = {} body[@bounds[:left_closed] ? :gte : :gt] = @range[:gt] if @range.key?(:gt) body[@bounds[:right_closed] ? :lte : :lt] = @range[:lt] if @range.key?(:lt) filter = {@name => body} filter[:_cache] = !![:cache] if .key?(:cache) filter.merge!(.slice(:execution)) {range: filter} end |
#__state__ ⇒ Object
41 42 43 |
# File 'lib/chewy/query/nodes/range.rb', line 41 def __state__ @range.merge(@bounds) end |