如何让MySQL把下划线看作全文搜索的词分隔符? [英] How to make MySQL treat underscore as a word separator for fulltext search?

查看:466
本文介绍了如何让MySQL把下划线看作全文搜索的词分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



这种行为可以通过其他方式更改吗?
这可能是通过搜索查询本身完成的吗?



我知道我可以用空格替换数据库中的所有下划线事件,但这会影响那些标题的原始完整性虽然。

解决方案


我知道我可以替换所有的下划线数据库中出现空格,但这会损害这些标题的原始完整性。


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

这允许您将下划线和聚合关键字替换为该字段(类别名称,作者,标签等)以增强搜索结果的相关性。
我们很多次成功地使用了这个功能,用于在搜索内容中推断HTML标签


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.

解决方案

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

这篇关于如何让MySQL把下划线看作全文搜索的词分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆