Class: ChefZero::Solr::Query::BinaryOperator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

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

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

Returns:

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

Returns:

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



11
12
13
# File 'lib/chef_zero/solr/query/binary_operator.rb', line 11

def to_s
  "(#{left} #{operator} #{right})"
end