blob: e10651939d413e17872ca21ad0088736f96f6177 (
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
42
43
44
45
|
require "chef_zero/solr/query/regexpable_query"
module ChefZero
module Solr
module Query
class Term < RegexpableQuery
def initialize(term)
# Get rid of escape characters, turn * and ? into .* and . for regex, and
# escape everything that needs escaping
literal_string = ""
regexp_string = ""
index = 0
while index < term.length
if term[index] == "*"
regexp_string << "#{WORD_CHARACTER}*"
literal_string = nil
index += 1
elsif term[index] == "?"
regexp_string << WORD_CHARACTER
literal_string = nil
index += 1
elsif term[index] == "~"
raise "~ unsupported"
else
if term[index] == '\\'
index = index + 1
if index >= term.length
raise "Backslash at end of string '#{term}'"
end
end
literal_string << term[index] if literal_string
regexp_string << Regexp.escape(term[index])
index += 1
end
end
super(regexp_string, literal_string)
end
def to_s
"Term(#{regexp_string})"
end
end
end
end
end
|