使用 Ruby on Rails 忽略 MySQL 查询中的重音
是否可以使用忽略重音符号的“=”或“like”操作来执行MySQL查询?
示例:
select * from address where name like "Rua Tabapua"
返回
Rua Tabapuá 塔巴普阿街 Rua Tabapuà
等...
是否可以使用 Ruby on Rails ActiveRecord API 而不使用 find_by_sql 来完成此操作?
谢谢,
鲁本
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这听起来像是一个 mysql 配置问题。
完成此查询后,检查 mysql.log 文件。您将看到查询已按照您的意愿进行,但 mysql 返回的结果比您预期的要多。
尝试在 mysql 控制台中查询,你会看到同样的事情发生。
所有这些都位于 Ruby on Rails 下面的一层中。
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.
您可以通过使用 UTF-8 和类似查询来做到这一点
You can do that by using UTF-8 and like queries
即使 MySQL 中可能有一些方法可以做到这一点,如果你想做全文搜索,也许使用像 Sphinx 和 Thinking Sphinx 这样的全文索引引擎会更容易。
通过 Sphinx 建立索引时,您可以对其进行配置,使其忽略重音字符等......
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...