Ignore accentuation in a MySQL query using Ruby on Rails
-
29-09-2019 - |
문제
Is it possible to execute a MySQL query using "=" or "like" operations that ignore accentuation?
Example:
select * from address where name like "Rua Tabapua"
returns
Rua Tabapuá Rua Tabapuã Rua Tabapuà
and etc...
Is it possible to do it using Ruby on Rails ActiveRecord API without using find_by_sql?
Thanks,
Rubem
해결책 3
You can do that by using UTF-8 and like queries
다른 팁
Even if there is probably some ways to do it in MySQL, if you want to do full text searching, maybe it would be easier to use a full text indexing engine like Sphinx and Thinking Sphinx.
When indexing via Sphinx, you can configure it so it would ignore accentuated characters and so on...
This sounds as a mysql configuration question. Check the mysql.log file when this query is done. You'll see the query is made as you wish, but mysql returns more results than you expect. Try the query in mysql console and you'll see same thing happens.
And all that in a layer below Ruby on Rails.