Class: ChefZero::Solr::Query::Term
- Inherits:
-
RegexpableQuery
- Object
- RegexpableQuery
- ChefZero::Solr::Query::Term
- Defined in:
- lib/chef_zero/solr/query/term.rb
Constant Summary
Constants inherited from RegexpableQuery
RegexpableQuery::DEFAULT_FIELD, RegexpableQuery::NON_WORD_CHARACTER, RegexpableQuery::WORD_CHARACTER
Instance Attribute Summary
Attributes inherited from RegexpableQuery
#literal_string, #regexp, #regexp_string
Instance Method Summary collapse
-
#initialize(term) ⇒ Term
constructor
A new instance of Term.
- #to_s ⇒ Object
Methods inherited from RegexpableQuery
#matches_doc?, #matches_values?
Constructor Details
#initialize(term) ⇒ Term
Returns a new instance of Term.
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 |
# File 'lib/chef_zero/solr/query/term.rb', line 7 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 += 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 |
Instance Method Details
#to_s ⇒ Object
39 40 41 |
# File 'lib/chef_zero/solr/query/term.rb', line 39 def to_s "Term(#{regexp_string})" end |