Class: Chewy::Query::Nodes::Equal

Inherits:
Expr show all
Defined in:
lib/chewy/query/nodes/equal.rb

Constant Summary collapse

EXECUTION =
{
  :| => :or,
  :or => :or,
  :& => :and,
  :and => :and,
  :b => :bool,
  :bool => :bool,
  :f => :fielddata,
  :fielddata => :fielddata
}.freeze

Instance Method Summary collapse

Methods inherited from Expr

#!, #&, #|, #~

Methods inherited from Base

#eql?, #render

Constructor Details

#initialize(name, value, *args) ⇒ Equal

Returns a new instance of Equal.



16
17
18
19
20
21
22
# File 'lib/chewy/query/nodes/equal.rb', line 16

def initialize(name, value, *args)
  @name = name.to_s
  @value = value
  @options = args.extract_options!
  execution = EXECUTION[args.first.to_sym] if args.first
  @options[:execution] = execution if execution
end

Instance Method Details

#__render__Object



24
25
26
27
28
29
30
# File 'lib/chewy/query/nodes/equal.rb', line 24

def __render__
  filter = (@value.is_a?(Array) ? :terms : :term)
  body = {@name => @value}
  body.merge!(@options.slice(:execution)) if filter == :terms
  body[:_cache] = !!@options[:cache] if @options.key?(:cache)
  {filter => body}
end