Mysql全文搜索不使用特殊字符

时间:2015-10-09 10:47:55

标签: mysql url full-text-search match

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

示例:在域表中,' 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

1 个答案:

答案 0 :(得分:1)

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

  

双引号(“"”)字符中的短语匹配   只有字体包含短语的行,因为它是键入的。

例如:

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

结果:

name
https://www.google.com

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

这是SQL小提琴:http://sqlfiddle.com/#!9/a6458/6