class OpenSearch::DSL::Search::Filter

Wraps the ‘filter` part of a search definition, aggregation, etc

Public Class Methods

new(*args, &block) click to toggle source
# File lib/opensearch/dsl/search/filter.rb, line 39
def initialize(*args, &block)
  @block = block
end

Public Instance Methods

call() click to toggle source

Evaluates any block passed to the query

@return [self]

# File lib/opensearch/dsl/search/filter.rb, line 60
def call
  @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block
  self
end
method_missing(name, *args, &block) click to toggle source

Looks up the corresponding class for a method being invoked, and initializes it

@raise [NoMethodError] When the corresponding class cannot be found

# File lib/opensearch/dsl/search/filter.rb, line 47
def method_missing(name, *args, &block)
  klass = Utils.__camelize(name)
  if Filters.const_defined? klass
    @value = Filters.const_get(klass).new *args, &block
  else
    raise NoMethodError, "undefined method '#{name}' for #{self}"
  end
end
to_hash(options={}) click to toggle source

Converts the query definition to a Hash

@return [Hash]

# File lib/opensearch/dsl/search/filter.rb, line 69
def to_hash(options={})
  call
  if @value
    @value.to_hash
  else
    {}
  end
end