class RediSearch::Spellcheck

Constants

Suggestion

Attributes

distance[RW]
documents[R]
index[RW]
terms[RW]

Public Class Methods

new(index, terms, distance: 1) click to toggle source
# File lib/redi_search/spellcheck.rb, line 14
def initialize(index, terms, distance: 1)
  @index = index
  @terms = terms
  @distance = distance
end

Private Instance Methods

command() click to toggle source
# File lib/redi_search/spellcheck.rb, line 25
def command
  ["SPELLCHECK", index.name, terms, "DISTANCE", distance]
end
execute() click to toggle source
# File lib/redi_search/spellcheck.rb, line 33
def execute
  validate!

  @loaded = true

  RediSearch.client.call!(*command).yield_self do |response|
    parse_response(response)
  end
end
parse_response(response) click to toggle source
# File lib/redi_search/spellcheck.rb, line 43
def parse_response(response)
  suggestions = response.map do |suggestion|
    suggestion[1..2]
  end.to_h

  @documents = parsed_terms.map do |term|
    Result.new(term, suggestions[term] || [])
  end
end
parsed_terms() click to toggle source
# File lib/redi_search/spellcheck.rb, line 29
def parsed_terms
  terms.split(Regexp.union(",.<>{}[]\"':;!@#$%^&*()-+=~\s".split("")))
end