class GroongaSynonym::Synonym

Attributes

term[R]
weight[R]

Public Class Methods

new(term, weight=nil) click to toggle source
# File lib/groonga-synonym/synonym.rb, line 20
def initialize(term, weight=nil)
  @term = term
  @weight = weight
end

Public Instance Methods

==(other) click to toggle source
# File lib/groonga-synonym/synonym.rb, line 34
def ==(other)
  other.is_a?(self.class) and
    @term == other.term and
    @weight == other.weight
end
eql?(other) click to toggle source
# File lib/groonga-synonym/synonym.rb, line 40
def eql?(other)
  self == other
end
hash() click to toggle source
# File lib/groonga-synonym/synonym.rb, line 44
def hash
  [@term, @weight].hash
end
to_groonga() click to toggle source
# File lib/groonga-synonym/synonym.rb, line 25
def to_groonga
  formatted = ""
  if @weight and @weight != 1.0
    formatted << ">" << ("%f" % (@weight - 1)).gsub(/0+\z/, "")
  end
  formatted << escape_term(@term)
  formatted
end

Private Instance Methods

escape_term(term) click to toggle source
# File lib/groonga-synonym/synonym.rb, line 49
def escape_term(term)
  return "\"#{term}\"" if term == "OR"
  term = term.gsub(/["()\\*:+-]/) do |matched|
    "\\#{matched}"
  end
  if term.include?(" ")
    "\"#{term}\""
  else
    term
  end
end