Class: ChefZero::Solr::Query::UnaryOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/chef_zero/solr/query/unary_operator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#operandObject (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

#operatorObject (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

Returns:

  • (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

Returns:

  • (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_sObject



10
11
12
# File 'lib/chef_zero/solr/query/unary_operator.rb', line 10

def to_s
  "#{operator} #{operand}"
end