On Oct 12, 2006, at 4:19 AM, soulhunter wrote:
Anyway, I found a way of implementing it, but I don’t quite like it
because it would implies create the autocomplete function for each
autocomplete I have in my project.
The way of doing so I found is to change the condition from:
LOWER(column) like ‘%thing_downcased%’
Just to share a different approach, since you can’t expect users to
type accented words correctly, I usually store a normalized extra
column (say name_normalized) for searches maintained in some Rails-
way like filters, or store just the normalization of them in ferret.
Then any query has to be normalized.
– fxn
Utility method that retursn an ASCIIfied, downcased, and
sanitized string.
It relies on the Unicode Hacks plugin by means of String#chars.
We assume
$KCODE is ‘u’ in environment.rb. By now we support a wide range
of latin
accented letters, based on the Unicode Character Palette bundled
in Macs.
def self.normalize(str)
n = str.chars.downcase.strip.to_s
n.gsub!(/[à áâãäåÄÄ?Ä?]/u, ‘a’)
n.gsub!(/\s+/, ’ ')
n.gsub!(/æ/u, ‘ae’)
n.gsub!(/[ÄÄ?]/u, ‘d’)
n.gsub!(/[çÄ?ÄÄ?Ä?]/u, ‘c’)
n.gsub!(/[èéêëÄ?Ä?Ä?Ä?Ä?]/u, ‘e’)
n.gsub!(/Æ?/u, ‘f’)
n.gsub!(/[ÄÄ?ġģ]/u, ‘g’)
n.gsub!(/[ĥħ]/, ‘h’)
n.gsub!(/[ììÃîïīĩÄ]/u, ‘i’)
n.gsub!(/[įıijĵ]/u, ‘j’)
n.gsub!(/[ķĸ]/u, ‘k’)
n.gsub!(/[Å?ľĺļÅ?]/u, ‘l’)
n.gsub!(/[ñÅ?Å?Å?Å?Å?]/u, ‘n’)
n.gsub!(/[òóôõöøÅÅ?ÅÅ]/u, ‘o’)
n.gsub!(/Å?/u, ‘oe’)
n.gsub!(/[Å?Å?Å?]/u, ‘r’)
n.gsub!(/[Å?Å¡Å?ÅÈ?]/u, ‘s’)
n.gsub!(/[ťţŧÈ?]/u, ‘t’)
n.gsub!(/[ùúûüūůűÅũų]/u, ‘u’)
n.gsub!(/ŵ/u, ‘w’)
n.gsub!(/[ýÿŷ]/u, ‘y’)
n.gsub!(/[žżź]/u, ‘z’)
n.gsub!(/[^\sa-z0-9_-]/, ‘’)
n
end