MySQL 全文布尔模式搜索 returns 结果太多

MySQL Fulltext Boolean Mode search returns too many results

我的全文搜索查询有问题,我几乎遍历了所有我能找到的论坛和话题,但我仍然遇到这个问题。

我正在使用 MySQL 全文布尔模式搜索 return 基于两列(艺术家姓名和曲目标题)匹配的行。用户可以在搜索栏中输入他们想要的任何短语,并且结果应该只是包含 EITHER 列中搜索查询的所有部分的行。

这是我目前的查询,它适用于大多数查询,但对于某些查询 return 结果过于松散,我不确定为什么。

SELECT * FROM tracks WHERE MATCH(artist, title) AGAINST('+paul +van +dyk ' IN BOOLEAN MODE)

然而,此查询包含 Paul 的 returns 行,没有 'Van' 或 'Dyk'。同样,我希望查询 return 仅包含艺术家或曲目名称列中所有关键字的行。

提前致谢

要增强布尔模式下结果的排序,您可以使用以下方法:

SELECT column_names, MATCH (text) AGAINST ('word1 word2 word3')
AS col1 FROM table1
WHERE MATCH (text) AGAINST ('+word1 +word2 +word3' in boolean mode) 
order by col1 desc;

首先使用MATCH()我们得到非布尔搜索模式的分数(更有特色)second MATCH() 确保我们真的只得到我们想要的结果(所有 3 个词)

因此您的查询将变为:

SELECT *, MATCH (artist, title) AGAINST ('paul van dyk')
    AS score FROM tracks
    WHERE MATCH (artist, title) 
    AGAINST ('+paul +van +dyk' in boolean mode) 
    order by score desc;

希望;你现在会得到更好的结果。

是否有效;请告诉我。

借用@Avidan 的回答。这些是可以对全文搜索执行的操作,以帮助创建您想要的查询。

The following examples demonstrate some search strings that use boolean full-text operators:

'apple banana'

Find rows that contain at least one of the two words.

'+apple +juice'

Find rows that contain both words.

'+apple macintosh'

Find rows that contain the word “apple”, but rank rows higher if they also contain “macintosh”.

'+apple -macintosh'

Find rows that contain the word “apple” but not “macintosh”.

'+apple ~macintosh'

Find rows that contain the word “apple”, but if the row also contains the word “macintosh”, rate it lower than if row does not. This is “softer” than a search for '+apple -macintosh', for which the presence of “macintosh” causes the row not to be returned at all.

'+apple +(>turnover

Find rows that contain the words “apple” and “turnover”, or “apple” and “strudel” (in any order), but rank “apple turnover” higher than “apple strudel”.

'apple*'

Find rows that contain words such as “apple”, “apples”, “applesauce”, or “applet”.

'"some words"'

文档:https://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html