douyu8187
douyu8187
2017-05-07 13:00
浏览 167
已采纳

在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)

图片转代码服务由CSDN问答提供 功能建议

我正在 php 中执行搜索功能,我允许 BOOLEAN 搜索,但是当我输入包含 @ 等字符的文本时,查询失败。

例如,当我搜索 @everyone时 ,它会抛出一个错误。 我尝试通过添加双引号来解决这个问题,但是它没有按预期工作,因为对于搜索 @everyone ,它可以工作但返回包含<的行 strong>每个人 @everone

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

这是我的查询(简化):

  SELECT * FROM messages WHERE MATCH(body)AGAINST('@ 每个人都在'BOOLEAN模式)
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douza19870617
    douza19870617 2017-05-07 13:06
    已采纳

    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.

    点赞 评论

相关推荐