Class: Elastic::Nodes::Boolean
- Includes:
- Concerns::Boostable
- Defined in:
- lib/elastic/nodes/boolean.rb
Instance Attribute Summary collapse
-
#disable_coord ⇒ Object
Returns the value of attribute disable_coord.
-
#minimum_should_match ⇒ Object
Returns the value of attribute minimum_should_match.
Attributes included from Concerns::Boostable
Class Method Summary collapse
Instance Method Summary collapse
- #clone ⇒ Object
- #filter(_node) ⇒ Object
- #filters ⇒ Object
- #filters=(_nodes) ⇒ Object
-
#initialize ⇒ Boolean
constructor
A new instance of Boolean.
- #must(_node) ⇒ Object
- #must_not(_node) ⇒ Object
- #must_nots ⇒ Object
- #must_nots=(_nodes) ⇒ Object
- #musts ⇒ Object
- #musts=(_nodes) ⇒ Object
- #render(_options = {}) ⇒ Object
- #should(_node) ⇒ Object
- #shoulds ⇒ Object
- #shoulds=(_nodes) ⇒ Object
- #simplify ⇒ Object
- #traverse(&_block) ⇒ Object
Methods inherited from Base
Methods included from Support::Traversable
Constructor Details
Instance Attribute Details
#disable_coord ⇒ Object
Returns the value of attribute disable_coord.
13 14 15 |
# File 'lib/elastic/nodes/boolean.rb', line 13 def disable_coord @disable_coord end |
#minimum_should_match ⇒ Object
Returns the value of attribute minimum_should_match.
13 14 15 |
# File 'lib/elastic/nodes/boolean.rb', line 13 def minimum_should_match @minimum_should_match end |
Class Method Details
.build_and(_nodes) ⇒ Object
5 6 7 |
# File 'lib/elastic/nodes/boolean.rb', line 5 def self.build_and(_nodes) new.tap { |n| n.musts = _nodes } end |
.build_or(_nodes) ⇒ Object
9 10 11 |
# File 'lib/elastic/nodes/boolean.rb', line 9 def self.build_or(_nodes) new.tap { |n| n.shoulds = _nodes } end |
Instance Method Details
#clone ⇒ Object
91 92 93 94 95 96 97 98 99 |
# 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) ⇒ Object
36 37 38 |
# File 'lib/elastic/nodes/boolean.rb', line 36 def filter(_node) @filters << _node end |
#filters ⇒ Object
68 69 70 |
# File 'lib/elastic/nodes/boolean.rb', line 68 def filters @filters.each end |
#filters=(_nodes) ⇒ Object
64 65 66 |
# File 'lib/elastic/nodes/boolean.rb', line 64 def filters=(_nodes) @filters = _nodes.dup.to_a end |
#must(_node) ⇒ Object
24 25 26 |
# File 'lib/elastic/nodes/boolean.rb', line 24 def must(_node) @musts << _node end |
#must_not(_node) ⇒ Object
28 29 30 |
# File 'lib/elastic/nodes/boolean.rb', line 28 def must_not(_node) @must_nots << _node end |
#must_nots ⇒ Object
52 53 54 |
# File 'lib/elastic/nodes/boolean.rb', line 52 def must_nots @must_nots.each end |
#must_nots=(_nodes) ⇒ Object
48 49 50 |
# File 'lib/elastic/nodes/boolean.rb', line 48 def must_nots=(_nodes) @must_nots = _nodes.dup.to_a end |
#musts ⇒ Object
44 45 46 |
# File 'lib/elastic/nodes/boolean.rb', line 44 def musts @musts.each end |
#musts=(_nodes) ⇒ Object
40 41 42 |
# File 'lib/elastic/nodes/boolean.rb', line 40 def musts=(_nodes) @musts = _nodes.dup.to_a end |
#render(_options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/elastic/nodes/boolean.rb', line 78 def render( = {}) hash = {} hash['must'] = @musts.map { |n| n.render() } if !@musts.empty? hash['must_not'] = @must_nots.map { |n| n.render() } if !@must_nots.empty? hash['should'] = @shoulds.map { |n| n.render() } if !@shoulds.empty? hash['filters'] = @filters.map { |n| n.render() } 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) ⇒ Object
32 33 34 |
# File 'lib/elastic/nodes/boolean.rb', line 32 def should(_node) @shoulds << _node end |
#shoulds ⇒ Object
60 61 62 |
# File 'lib/elastic/nodes/boolean.rb', line 60 def shoulds @shoulds.each end |
#shoulds=(_nodes) ⇒ Object
56 57 58 |
# File 'lib/elastic/nodes/boolean.rb', line 56 def shoulds=(_nodes) @shoulds = _nodes.dup.to_a end |
#simplify ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# 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) ⇒ Object
72 73 74 75 76 |
# 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 |