Documentation Home
MySQL 8.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 294.0Kb
Man Pages (Zip) - 409.0Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb
Excerpts from this Manual

MySQL 8.3 Reference Manual  /  ...  /  Full-Text Searches with Query Expansion

14.9.3 全文搜索与查询扩展

全文搜索支持查询扩展(特别是其变体“盲查询扩展”)。这在搜索短语太短时非常有用,通常意味着用户依赖于隐含知识,而全文搜索引擎缺乏这种知识。例如,用户搜索“数据库”可能实际上意味着“MySQL”、“Oracle”、“DB2”和“RDBMS”都是应该匹配“数据库”的短语,并且应该被返回。这是隐含知识。

盲查询扩展(也称为自动相关反馈)可以通过在搜索短语后添加WITH QUERY EXPANSIONIN NATURAL LANGUAGE MODE WITH QUERY EXPANSION来启用。它的工作方式是执行两次搜索,其中第二次搜索的搜索短语是原始搜索短语与第一次搜索中最相关的几篇文档的连接。因此,如果这些文档中有一篇包含“数据库”和“MySQL”的词语,那么第二次搜索将找到包含“MySQL”的文档,即使它们不包含“数据库”词语。以下示例显示了这种差异:

mysql> SELECT * FROM articles
    WHERE MATCH (title,body)
    AGAINST ('database' IN NATURAL LANGUAGE MODE);
+----+-------------------+------------------------------------------+
| id | title             | body                                     |
+----+-------------------+------------------------------------------+
|  1 | MySQL Tutorial    | DBMS stands for DataBase ...             |
|  5 | MySQL vs. YourSQL | In the following database comparison ... |
+----+-------------------+------------------------------------------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM articles
    WHERE MATCH (title,body)
    AGAINST ('database' WITH QUERY EXPANSION);
+----+-----------------------+------------------------------------------+
| id | title                 | body                                     |
+----+-----------------------+------------------------------------------+
|  5 | MySQL vs. YourSQL     | In the following database comparison ... |
|  1 | MySQL Tutorial        | DBMS stands for DataBase ...             |
|  3 | Optimizing MySQL      | In this tutorial we show ...             |
|  6 | MySQL Security        | When configured properly, MySQL ...      |
|  2 | How To Use MySQL Well | After you went through a ...             |
|  4 | 1001 MySQL Tricks     | 1. Never run mysqld as root. 2. ...      |
+----+-----------------------+------------------------------------------+
6 rows in set (0.00 sec)

另一个示例可能是搜索乔治·西梅农(Georges Simenon)关于马格雷特(Maigret)的书籍,当用户不确定如何拼写“马格雷特”。搜索“梅格雷和不情愿的证人”只找到“马格雷特和不情愿的证人”,而使用查询扩展则找到所有包含“马格雷特”词语的书籍。

Note

由于盲查询扩展倾向于显著增加噪音,返回非相关文档,因此只有在搜索短语很短时才使用它。