简体   繁体   English

在mysql全文搜索中搜索特殊字符

[英]Search for special chars in mysql full text search

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.我正在php执行搜索功能,并且允许BOOLEAN搜索,但是当我输入包含@字符的文本时,查询失败。

For example, when I search for @everyone , it throws an error.例如,当我搜索@everyone 时,它会引发错误。 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 .我试图通过添加双引号来解决这个问题,但它没有按预期工作,因为对于搜索@everyone ,它工作但返回包含每个人和@everone 的行。

I would like to know how we can search for words containing special chars in mysql full text search我想知道如何在mysql全文搜索中搜索包含特殊字符的单词

Here's my query (simplified) :这是我的查询(简化):

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

By default, MySQL does not treat '@' as a valid character for a word.默认情况下,MySQL 不会将'@'视为单词的有效字符。 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.进行更改后,您将需要重新构建索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM