class Elastic::Nodes::Nested

Constants

SCORE_MODES

Attributes

child[RW]
path[RW]
score_mode[R]

Public Class Methods

build(_path, _child) click to toggle source
# File lib/elastic/nodes/nested.rb, line 5
def self.build(_path, _child)
  new.tap do |node|
    node.path = _path
    node.child = _child
  end
end

Public Instance Methods

clone() click to toggle source
Calls superclass method Elastic::Nodes::Base#clone
# File lib/elastic/nodes/nested.rb, line 20
def clone
  prepare_clone super, @child.clone
end
render(_options = {}) click to toggle source
# File lib/elastic/nodes/nested.rb, line 40
def render(_options = {})
  path = @path
  path = "#{_options[:query_path]}.#{path}" if _options.key? :query_path

  hash = {
    'path' => path,
    'query' => @child.render(_options.merge(query_path: path))
  }

  hash['score_mode'] = @score_mode.to_s if @score_mode && @score_mode != :avg

  { "nested" => hash }
end
score_mode=(_value) click to toggle source
# File lib/elastic/nodes/nested.rb, line 24
def score_mode=(_value)
  raise ArgumentError, "invalid score mode #{_value}" if _value && !SCORE_MODES.include?(_value)
  @score_mode = _value
end
simplify() click to toggle source
Calls superclass method Elastic::Nodes::Base#simplify
# File lib/elastic/nodes/nested.rb, line 29
def simplify
  new_child = @child.simplify
  if new_child.is_a? Nested
    prepare_clone(super, new_child.child).tap do |clone|
      clone.path = "#{clone.path}.#{new_child.path}"
    end
  else
    prepare_clone super, new_child
  end
end
traverse(&_block) click to toggle source
Calls superclass method Elastic::Nodes::Base#traverse
# File lib/elastic/nodes/nested.rb, line 15
def traverse(&_block)
  super
  @child.traverse(&_block)
end

Private Instance Methods

prepare_clone(_clone, _child) click to toggle source
# File lib/elastic/nodes/nested.rb, line 56
def prepare_clone(_clone, _child)
  _clone.path = @path
  _clone.child = _child
  _clone.score_mode = @score_mode
  _clone
end