在mysql全文搜索中搜索特殊字符 [英] Search for special chars in mysql full text search

查看:201
本文介绍了在mysql全文搜索中搜索特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在php中执行搜索功能,并且允许BOOLEAN搜索,但是当我输入包含诸如@之类的字符的文本时,查询将失败.

I am doing a search function in php, and I am allowing BOOLEAN search, but when I enter text containing chars like @, the query fails.

例如,当我搜索 @everyone 时,它会引发错误. 我尝试通过添加双引号来解决此问题,但由于没有达到预期效果,因为对于搜索 @everyone ,它可以工作,但返回包含所有人的行@everone .

For example, when I search for @everyone, it throws an error. I tried to solve this by adding doublequotes, but it doesn't work as expected, since for the search @everyone, it works but returns rows containing everyone and @everone.

我想知道如何在mysql全文搜索中搜索包含特殊字符的单词

I would like to know how we can search for words containing special chars in mysql full text search

这是我的查询(简体):

Here's my query (simplified) :

SELECT * FROM messages WHERE MATCH(body) AGAINST ('@everyone' IN BOOLEAN MODE)

推荐答案

默认情况下,MySQL不会将'@'视为单词的有效字符.如果要使用'@',请查看文档.

By default, MySQL does not treat '@' as a valid character for a word. If you want to treat '@' it, then review the documentation on the subject.

进行更改后,您将需要重新构建索引.

After you have made the changes, then you will need to re-build your index.

这篇关于在mysql全文搜索中搜索特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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