class Elastic::Nodes::Boolean

Attributes

disable_coord[RW]
minimum_should_match[RW]

Public Class Methods

build_and(_nodes) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 5
def self.build_and(_nodes)
  new.tap { |n| n.musts = _nodes }
end
build_or(_nodes) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 9
def self.build_or(_nodes)
  new.tap { |n| n.shoulds = _nodes }
end
new() click to toggle source
Calls superclass method
# File lib/elastic/nodes/boolean.rb, line 15
def initialize
  super
  @musts = []
  @must_nots = []
  @shoulds = []
  @filters = []
  @disable_coord = !Elastic.config.coord_similarity
end

Public Instance Methods

clone() click to toggle source
# File lib/elastic/nodes/boolean.rb, line 91
def clone
  prepare_clone(
    super,
    @musts.map(&:clone),
    @must_nots.map(&:clone),
    @shoulds.map(&:clone),
    @filters.map(&:clone)
  )
end
filter(_node) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 36
def filter(_node)
  @filters << _node
end
filters() click to toggle source
# File lib/elastic/nodes/boolean.rb, line 68
def filters
  @filters.each
end
filters=(_nodes) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 64
def filters=(_nodes)
  @filters = _nodes.dup.to_a
end
must(_node) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 24
def must(_node)
  @musts << _node
end
must_not(_node) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 28
def must_not(_node)
  @must_nots << _node
end
must_nots() click to toggle source
# File lib/elastic/nodes/boolean.rb, line 52
def must_nots
  @must_nots.each
end
must_nots=(_nodes) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 48
def must_nots=(_nodes)
  @must_nots = _nodes.dup.to_a
end
musts() click to toggle source
# File lib/elastic/nodes/boolean.rb, line 44
def musts
  @musts.each
end
musts=(_nodes) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 40
def musts=(_nodes)
  @musts = _nodes.dup.to_a
end
render(_options = {}) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 78
def render(_options = {})
  hash = {}
  hash['must'] = @musts.map { |n| n.render(_options) } if !@musts.empty?
  hash['must_not'] = @must_nots.map { |n| n.render(_options) } if !@must_nots.empty?
  hash['should'] = @shoulds.map { |n| n.render(_options) } if !@shoulds.empty?
  hash['filters'] = @filters.map { |n| n.render(_options) } if !@filters.empty?
  hash['minimum_should_match'] = minimum_should_match unless minimum_should_match.nil?
  hash['disable_coord'] = true if disable_coord
  render_boost(hash)

  { "bool" => hash }
end
should(_node) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 32
def should(_node)
  @shoulds << _node
end
shoulds() click to toggle source
# File lib/elastic/nodes/boolean.rb, line 60
def shoulds
  @shoulds.each
end
shoulds=(_nodes) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 56
def shoulds=(_nodes)
  @shoulds = _nodes.dup.to_a
end
simplify() click to toggle source
# File lib/elastic/nodes/boolean.rb, line 101
def simplify
  new_must = @musts.map(&:simplify)
  new_must_not = @must_nots.map(&:simplify)
  new_should = @shoulds.map(&:simplify)
  new_filter = @filters.map(&:simplify)

  # TODO: detect must elements with boost = 0 and move them to "filter"

  total_nodes = new_must.length + new_must_not.length + new_should.length + new_filter.length
  if boost.nil? && total_nodes == 1
    return new_must.first if !new_must.empty?
    return new_should.first if !new_should.empty? # at least 1 should match
  end

  prepare_clone(super, new_must, new_must_not, new_should, new_filter)
end
traverse(&_block) click to toggle source
Calls superclass method Elastic::Nodes::Base#traverse
# File lib/elastic/nodes/boolean.rb, line 72
def traverse(&_block)
  super
  @shoulds.each { |c| c.traverse(&_block) }
  @musts.each { |c| c.traverse(&_block) }
end

Private Instance Methods

prepare_clone(_clone, _musts, _must_nots, _shoulds, _filters) click to toggle source
# File lib/elastic/nodes/boolean.rb, line 120
def prepare_clone(_clone, _musts, _must_nots, _shoulds, _filters)
  _clone.musts = _musts
  _clone.must_nots = _must_nots
  _clone.shoulds = _shoulds
  _clone.filters = _filters
  _clone.minimum_should_match = @minimum_should_match
  _clone.disable_coord = @disable_coord
  _clone
end