Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created September 14, 2010 17:06
Show Gist options
  • Save ayosec/579368 to your computer and use it in GitHub Desktop.
Save ayosec/579368 to your computer and use it in GitHub Desktop.
map = [
"âãäåāăąÁÂÃÄÅĀĂĄèééêëēĕėęěĒĔĖĘĚìíîïìĩīĭÌÍÎÏÌĨĪĬóôõöōŏőÒÓÔÕÖŌŎŐùúûüũūŭůÙÚÛÜŨŪŬŮñÑçÇüÜ".mb_chars,
"aaaaaaaaaaaaaaaeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiooooooooooooooouuuuuuuuuuuuuuuunnccuu"
]
# ActiveSupport::Multibyte::Chars#tr broken?
word = "anything"
adapted_word = "%#{word.mb_chars.split(//).map {|e| (p = map[0].index(e)) ? map[1][p,1] : e.to_s }.join.downcase}%"
Post.where("lower(translate(title, '#{map[0]}', '#{map[1]}')) like #{Post.connection.quote word}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment