Class: ChefZero::Solr::Query::BinaryOperator
- Inherits:
-
Object
- Object
- ChefZero::Solr::Query::BinaryOperator
- Defined in:
- lib/chef_zero/solr/query/binary_operator.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
-
#initialize(left, operator, right) ⇒ BinaryOperator
constructor
A new instance of BinaryOperator.
- #matches_doc?(doc) ⇒ Boolean
- #matches_values?(values) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(left, operator, right) ⇒ BinaryOperator
Returns a new instance of BinaryOperator.
5 6 7 8 9 |
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 5 def initialize(left, operator, right) @left = left @operator = operator @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
15 16 17 |
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 15 def left @left end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
16 17 18 |
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 16 def operator @operator end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
17 18 19 |
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 17 def right @right end |
Instance Method Details
#matches_doc?(doc) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 19 def matches_doc?(doc) case @operator when "AND" left.matches_doc?(doc) && right.matches_doc?(doc) when "OR" left.matches_doc?(doc) || right.matches_doc?(doc) when "^" left.matches_doc?(doc) when ":" if left.respond_to?(:literal_string) && left.literal_string values = doc[left.literal_string] else values = doc.matching_values { |key| left.matches_values?([key]) } end right.matches_values?(values) end end |
#matches_values?(values) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 37 def matches_values?(values) case @operator when "AND" left.matches_values?(values) && right.matches_values?(values) when "OR" left.matches_values?(values) || right.matches_values?(values) when "^" left.matches_values?(values) when ":" raise ": does not work inside a : or term" end end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 11 def to_s "(#{left} #{operator} #{right})" end |