在mysql全文搜索中搜索特殊字符
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.
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.
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)
我正在 例如,当我搜索 @everyone时 strong>,它会抛出一个错误。
我尝试通过添加双引号来解决这个问题,但是它没有按预期工作,因为对于搜索 @everyone strong>,它可以工作但返回包含每个人 strong>和 @everone strong>。 p>
我想知道如何在 这是我的查询(简化): p>
php code>中执行搜索功能,我允许
BOOLEAN code>搜索,但是当我输入包含
@ code>等字符的文本时,查询失败。 p>
mysql中搜索包含特殊字符的单词 代码>全文搜索 p>
SELECT * FROM messages WHERE MATCH(body)AGAINST('@ 每个人都在'BOOLEAN模式)
code> pre>
div>
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.