Class: Elastic::Nodes::Nested

Inherits:
Base
  • Object
show all
Defined in:
lib/elastic/nodes/nested.rb

Constant Summary collapse

SCORE_MODES =
[:avg, :sum, :min, :max, :none]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #handle_result

Methods included from Support::Traversable

#pick

Instance Attribute Details

#childObject

Returns the value of attribute child.



12
13
14
# File 'lib/elastic/nodes/nested.rb', line 12

def child
  @child
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/elastic/nodes/nested.rb', line 12

def path
  @path
end

#score_modeObject

Returns the value of attribute score_mode.



13
14
15
# File 'lib/elastic/nodes/nested.rb', line 13

def score_mode
  @score_mode
end

Class Method Details

.build(_path, _child) ⇒ Object



5
6
7
8
9
10
# 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

Instance Method Details

#cloneObject



20
21
22
# File 'lib/elastic/nodes/nested.rb', line 20

def clone
  prepare_clone super, @child.clone
end

#render(_options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# 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

#simplifyObject



29
30
31
32
33
34
35
36
37
38
# 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) ⇒ Object



15
16
17
18
# File 'lib/elastic/nodes/nested.rb', line 15

def traverse(&_block)
  super
  @child.traverse(&_block)
end