Mysql 全文搜索不支持特殊字符

Mysql fulltext search not working with special characters

问题:我使用的是 MYSQL 和 PHP 最新版本。我们在 MYSQL 全文搜索中遇到了这个问题。它不适用于特殊字符。

示例:在域 table 中,'name' 字段具有以下三个值:

1. https://www.google.com 
2. https://www.yahoo.com
3. https://www.trafe.com

如果我使用搜索词 https://www.google.com,它会显示以上三个值作为结果,但正确答案是 https://www.google.com.

查询:

SELECT name 
FROM domains 
WHERE MATCH (name) AGAINST ('https://www.google.com*' IN BOOLEAN MODE);

实际结果:https://www.google.com

使用双引号:https://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

A phrase that is enclosed within double quote (“"”) characters matches only rows that contain the phrase literally, as it was typed.

例如:

SELECT name 
FROM domains 
WHERE MATCH (name) AGAINST ('"https://www.google.com"' IN BOOLEAN MODE);

结果:

name
https://www.google.com

如果你真的想要 * 你可以搜索 '"https://www.google.com*"'* 放在双引号内)。

这里是SQLfiddle:http://sqlfiddle.com/#!9/a6458/6