summaryrefslogtreecommitdiff
path: root/lib/chef_zero/solr/query/unary_operator.rb
blob: e83683c78f5791f313aa3b1067db43b9940836e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module ChefZero
  module Solr
    module Query
      class UnaryOperator
        def initialize(operator, operand)
          @operator = operator
          @operand = operand
        end

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

        attr_reader :operator
        attr_reader :operand

        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

        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
      end
    end
  end
end