简体   繁体   中英

Ignore accentuation in a MySQL query using Ruby on Rails

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

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...

您可以使用UTF-8和类似的查询来实现

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM