使用 Ruby on Rails 忽略 MySQL 查询中的重音

发布于 2024-09-30 17:11:04 字数 289 浏览 1 评论 0原文

是否可以使用忽略重音符号的“=”或“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情仇皆在手 2024-10-07 17:11:06

这听起来像是一个 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.

半仙 2024-10-07 17:11:06

您可以通过使用 UTF-8 和类似查询来做到这一点

You can do that by using UTF-8 and like queries

挽清梦 2024-10-07 17:11:05

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文