Class: IndexedSearch::Match::Soundex

Inherits:
Base
  • Object
show all
Defined in:
lib/indexed_search/match/soundex.rb

Overview

Does a soundex algorithm comparison to find words that sound similar. Only works well for English. Requires the Text gem.

Uses a soundex column to store a soundex value with each entry in the IndexedSearch::Word model.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#find, find_attributes, #initialize, match_against_term?, #results, #term_matches, #term_non_matches

Constructor Details

This class inherits a constructor from IndexedSearch::Match::Base

Class Method Details

.make_index_value(term) ⇒ Object



38
39
40
# File 'lib/indexed_search/match/soundex.rb', line 38

def self.make_index_value(term)
  Text::Soundex.soundex(term)
end

Instance Method Details

#scopeObject



28
29
30
# File 'lib/indexed_search/match/soundex.rb', line 28

def scope
  @scope.where(self.class.matcher_attribute => term_map.keys)
end

#term_mapObject



32
33
34
35
36
# File 'lib/indexed_search/match/soundex.rb', line 32

def term_map
  @term_map ||= Hash.new { |hash,key| hash[key] = [] }.tap do |map|
    term_matches.each { |term| map[self.class.make_index_value(term)] << term }
  end
end