Class: ChefZero::Solr::Query::UnaryOperator
- Inherits:
-
Object
- Object
- ChefZero::Solr::Query::UnaryOperator
- Defined in:
- lib/chef_zero/solr/query/unary_operator.rb
Instance Attribute Summary collapse
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
Instance Method Summary collapse
-
#initialize(operator, operand) ⇒ UnaryOperator
constructor
A new instance of UnaryOperator.
- #matches_doc?(doc) ⇒ Boolean
- #matches_values?(values) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(operator, operand) ⇒ UnaryOperator
Returns a new instance of UnaryOperator.
5 6 7 8 |
# File 'lib/chef_zero/solr/query/unary_operator.rb', line 5 def initialize(operator, operand) @operator = operator @operand = operand end |
Instance Attribute Details
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
15 16 17 |
# File 'lib/chef_zero/solr/query/unary_operator.rb', line 15 def operand @operand end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
14 15 16 |
# File 'lib/chef_zero/solr/query/unary_operator.rb', line 14 def operator @operator end |
Instance Method Details
#matches_doc?(doc) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/chef_zero/solr/query/unary_operator.rb', line 17 def matches_doc?(doc) case @operator when "-", "NOT", "!" !operand.matches_doc?(doc) when "+" # TODO This operator uses relevance to eliminate other, unrelated # expressions. +a OR b means "if it has b but not a, don't return it" raise "+ not supported yet, because it is hard." end end |
#matches_values?(values) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chef_zero/solr/query/unary_operator.rb', line 28 def matches_values?(values) case @operator when "-", "NOT", "!" !operand.matches_values?(values) when "+" # TODO This operator uses relevance to eliminate other, unrelated # expressions. +a OR b means "if it has b but not a, don't return it" raise "+ not supported yet, because it is hard." end end |
#to_s ⇒ Object
10 11 12 |
# File 'lib/chef_zero/solr/query/unary_operator.rb', line 10 def to_s "#{operator} #{operand}" end |