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, }
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 @options = args. @range = @options.reject { |k, v| ![:gt, :lt].include?(k) } @bounds = @options.reject { |k, v| ![:left_closed, :right_closed].include?(k) } execution = EXECUTION[args.first.to_sym] if args.first @options[: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] || @options[:cache] state[:cache] = cache unless cache.nil? execution = other.[:execution] || @options[: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 @options 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] = !!@options[:cache] if @options.key?(:cache) filter.merge!(@options.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 |