Class: Stretchy::AndCollector
- Inherits:
-
Object
- Object
- Stretchy::AndCollector
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/stretchy/and_collector.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #boost_nodes ⇒ Object
- #context?(*args) ⇒ Boolean
- #function_score_node? ⇒ Boolean
-
#initialize(nodes, context = {}) ⇒ AndCollector
constructor
A new instance of AndCollector.
- #node ⇒ Object
- #query_nodes ⇒ Object
- #with_context(new_context) ⇒ Object
Constructor Details
#initialize(nodes, context = {}) ⇒ AndCollector
Returns a new instance of AndCollector.
11 12 13 14 |
# File 'lib/stretchy/and_collector.rb', line 11 def initialize(nodes, context = {}) @nodes = nodes @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/stretchy/and_collector.rb', line 9 def context @context end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
9 10 11 |
# File 'lib/stretchy/and_collector.rb', line 9 def nodes @nodes end |
Instance Method Details
#boost_nodes ⇒ Object
38 39 40 |
# File 'lib/stretchy/and_collector.rb', line 38 def boost_nodes @boost_nodes ||= nodes.select {|n| n.context? :boost } end |
#context?(*args) ⇒ Boolean
20 21 22 |
# File 'lib/stretchy/and_collector.rb', line 20 def context?(*args) args.all? {|c| !!context[c] } end |
#function_score_node? ⇒ Boolean
42 43 44 |
# File 'lib/stretchy/and_collector.rb', line 42 def function_score_node? boost_nodes.reject { |n| n.empty? }.any? end |
#node ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/stretchy/and_collector.rb', line 24 def node @node ||= if function_score_node? function_score_node elsif query_nodes.any? query_node else Node.new({match_all: {}}, context) end end |
#query_nodes ⇒ Object
34 35 36 |
# File 'lib/stretchy/and_collector.rb', line 34 def query_nodes @query_nodes ||= nodes.reject {|n| n.context? :boost } end |
#with_context(new_context) ⇒ Object
16 17 18 |
# File 'lib/stretchy/and_collector.rb', line 16 def with_context(new_context) self.class.new nodes, new_context end |