summaryrefslogtreecommitdiff
path: root/lib/chef_zero/solr/query/phrase.rb
blob: ed7cc65868590a8bbae4fd4a1e5d31247f00fc80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require_relative "regexpable_query"

module ChefZero
  module Solr
    module Query
      class Phrase < RegexpableQuery
        def initialize(terms)
          # Phrase is terms separated by whitespace
          if terms.size == 0 && terms[0].literal_string
            literal_string = terms[0].literal_string
          else
            literal_string = nil
          end
          super(terms.map(&:regexp_string).join("#{NON_WORD_CHARACTER}+"), literal_string)
        end

        def to_s
          "Phrase(\"#{@regexp_string}\")"
        end
      end
    end
  end
end