MySQL MATCH AGAINST使用通配符返回带有撇号的意外结果

时间:2015-03-11 14:18:02

标签: mysql regex

我正在进行全文搜索,因为用户输入并遇到了一个不符合我预期的实例。

我在一个包含全文索引的列中包含以下数据:

  1. Adrienna O'ROURKE O'ROURKE Adrienna F 1949-04-09 Miss Single 6908

  2. Olivia O'Toole O'Toole Olivia F 1989-06-30 Miss Single 4362

  3. Owen O'Leary O'Leary Owen M 1979-01-12 Mr. Single 4533

  4. 下面的查询无法匹配“O'Rourke”,但是将行与“O'Toole”和“O'Leary”匹配:

    SELECT distinct o.*
    FROM pcObjects o  
    WHERE  MATCH(ObjectSearchData) AGAINST('*O\'*' IN BOOLEAN MODE)
    ORDER BY MATCH(ObjectSearchData) AGAINST('*O\'*' IN BOOLEAN MODE) DESC
    

    此查询与“O'Rourke”条目匹配:

    SELECT distinct o.*
    FROM pcObjects o  
    WHERE  MATCH(ObjectSearchData) AGAINST('*O\'Rou*' IN BOOLEAN MODE)
    ORDER BY MATCH(ObjectSearchData) AGAINST('*O\'Rou*' IN BOOLEAN MODE) DESC
    

    有人可以解释为什么“O'Rourke”在第一时间没有找到,但“O'Toole”是?感谢。

1 个答案:

答案 0 :(得分:0)

据我所知BOOLEAN模式返回1或0,没有浮点相关值,所以你只需要:

SELECT distinct o.*
FROM pcObjects o  
WHERE  MATCH(ObjectSearchData) AGAINST('O\'' IN BOOLEAN MODE)

这一行:

ORDER BY MATCH(ObjectSearchData) AGAINST('*O\'*' IN BOOLEAN MODE) DESC

BOOLEAN模式下无意义所有行都 MATCH = 1