如何让MySQL将下划线作为全文搜索的单词分隔符?

发布于 2024-08-20 20:24:27 字数 289 浏览 5 评论 0原文

我正在使用 MySQL 全文和 PHP (codeigniter) 来搜索包含 RSS 项目的数据库。问题是其中一些项目的标题使用下划线而不是空格。由于 MySQL 将下划线视为单词的一部分,因此这些项目在搜索中永远不会匹配,除非用户键入包含下划线的确切标题。

服务器是共享的,所以我无权访问 MySQL 服务器系统变量。

可以通过其他方式改变这种行为吗? 这可以通过搜索查询本身来完成吗?

我知道我可以用空格替换数据库中出现的所有下划线,但这会损害这些标题的原始完整性。只是想知道是否还有另一种方法可以做到这一点。

I am using MySQL fulltext and PHP (codeigniter) to search a database containing RSS items. Problem is some of these items's titles use underscores instead of spaces. Since MySQL considers underscores as part of a word, these items will never be matched in the search, unless the user types the exact title including underscores.

Server is shared so I don't have access to MySQL Server System Variables.

Can this behavior be changed in some other way?
Can this maybe be done through the search query itself?

I know I could just replace all underscore occurrences in the DB by spaces, but this would compromise the original integrity of those titles though. Just wondering if there's another way of doing this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

北方的韩爷 2024-08-27 20:24:27

我知道我可以用空格替换数据库中出现的所有下划线,但这会损害这些标题的原始完整性。只是想知道是否还有其他方法可以做到这一点。

您可以使用专用于全文搜索的单独字段,而不是替换原始标题字段中的下划线。

这允许您替换下划线,并将关键字聚合到该字段(类别名称、作者、标签等)以增强搜索结果的相关性。
我们多次使用此方法,成功地摆脱了搜索内容推断中的 HTML 标签

I know I could just replace all underscore occurrences in the DB by spaces, but this would compromise the original integrity of those titles though. Just wondering if there's another way of doing this.

You can instead of replacing underscores in original title field, use a separate field dedicated to fulltext searches.

This allows you to replace underscores, plus aggregates keywords into this field (category names, authors, tags, etc.) to enhance search results relevance.
We used this a lot of times with success for getting rid of HTML tags in content infering with search

ゝ偶尔ゞ 2024-08-27 20:24:27

我认为如果不访问服务器就无法完成此操作。我见过的唯一方法是对 此 mySQL 手册页(“如何将 '-' 添加到单词字符列表中”)。它需要停止服务器并更改内部配置。

您最好的选择可能是创建第二列并删除下划线,然后进行搜索。

I don't think this can be done without access to the server. The only way I have ever seen to do it is the first comment on this mySQL manual page ("How I added '-' to the list of word characters"). It requires stopping the server and changing internal configuration.

Your best bet is probably creating a second column with removed underscores, and to search that.

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