class ChefZero::Solr::Query::Term

Public Class Methods

new(term) click to toggle source
# 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

Public Instance Methods

to_s() click to toggle source
# File lib/chef_zero/solr/query/term.rb, line 39
def to_s
  "Term(#{regexp_string})"
end