MySQL:为什么全文分数总是1?

发布于 2024-11-18 03:48:22 字数 432 浏览 3 评论 0原文

如果我运行此查询并打印每行的分数,它们始终为 1:

以下是一些示例查询结果:

First     |  Last     | Score
------------------------------
Jonathan  |  Bush     | 1
Joshua    |  Gilbert  | 1
Jon       |  Jonas    | 1

这是我运行的查询:

SELECT First, Last, MATCH(First, Last) AGAINST ('Jon' IN BOOLEAN MODE) AS score 
FROM users 
WHERE MATCH(First, Last) AGAINST('Jon' IN BOOLEAN MODE)
ORDER BY score DESC;

If I run this query and print the score of each rows, they are always 1:

Here are some sample query results:

First     |  Last     | Score
------------------------------
Jonathan  |  Bush     | 1
Joshua    |  Gilbert  | 1
Jon       |  Jonas    | 1

And this is the query that I run:

SELECT First, Last, MATCH(First, Last) AGAINST ('Jon' IN BOOLEAN MODE) AS score 
FROM users 
WHERE MATCH(First, Last) AGAINST('Jon' IN BOOLEAN MODE)
ORDER BY score DESC;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷路的信 2024-11-25 03:48:22

BOOLEAN MODE 仅支持二进制答案,无论搜索字符串是否出现在列中,都表示 0 或 1。要获得小数结果来计算权重,您必须在索引列上使用 match-against。

您可以通过这种方式使用布尔模式来获取高度:

SELECT *, ((1.3 * (MATCH(column1) AGAINST ('query' IN BOOLEAN MODE))) +
(0.6 * (MATCH(column2) AGAINST ('query' IN BOOLEAN MODE)))) AS relevance
FROM table WHERE ( MATCH(column1,column2) AGAINST
('query' IN BOOLEAN MODE) ) ORDER BY relevance DESC

布尔模式的优点是您可以在非索引列上使用它,但只能使用 0,1 作为结果,非布尔模式返回十进制结果,但只能应用于索引列...另请参阅 这里

The BOOLEAN MODE supports only binary answers, means 0 or 1 whether the search string appears in the column or not. To get a decimal result to calculate a weight, you have to use match-against on indexed columns.

You can use the boolean mode this way to get your wheight either:

SELECT *, ((1.3 * (MATCH(column1) AGAINST ('query' IN BOOLEAN MODE))) +
(0.6 * (MATCH(column2) AGAINST ('query' IN BOOLEAN MODE)))) AS relevance
FROM table WHERE ( MATCH(column1,column2) AGAINST
('query' IN BOOLEAN MODE) ) ORDER BY relevance DESC

The advantage of the boolean mode is that you can use it on non-indexed columns but only with 0,1 as result, the non-boolean mode returns a decimal result but can only be applied on indexed columns... see also here.

剩一世无双 2024-11-25 03:48:22

接受的答案部分正确。根据 MySQL 文档,MATCH AGAINST 可以返回浮点数。数据库引擎(如果是 MyISAM)只会在匹配时返回 1。使用 MATCH AGAINST 的 InnoDB 全文搜索将返回浮点数,以便可以按匹配结果对更高质量的匹配进行排序。

The accepted answer is partially correct. According to the MySQL docs, MATCH AGAINST can return floats. The database engine, if MyISAM, will only return 1 on match. InnoDB fulltext searches with MATCH AGAINST will return floats so that higher quality matches can be ordered by the match result.

三月梨花 2024-11-25 03:48:22

使用 NATURAL MODE 作为分数:

SELECT First, Last, MATCH(First, Last) AGAINST ('Jon') AS score 
FROM users 
WHERE MATCH(First, Last) AGAINST('+Jon' IN BOOLEAN MODE)
ORDER BY score DESC;

注意: 注意 + 运算符。此功能仅适用于BOOLEAN MODE

为什么我建议使用 NATURAL MODE 按相关性排序,因为它会返回 Jon Chris

Jon Chris        | Jonas
Jon Martin Chris | Jonas

并且 BOOLEAN MODE 可以 返回对于 +Jon +Chris

Jon Martin Chris | Jonas
Jon Chris        | Jonas

这是因为在 BOOLEAN MODE 中找到了两个单词,返回分数 2,但 NATURAL MODE 为第一个单词添加了更多分数条目,因为它是直接的点击和/或直接跟随单词会返回更好的搜索结果。

Use the result of NATURAL MODE as score:

SELECT First, Last, MATCH(First, Last) AGAINST ('Jon') AS score 
FROM users 
WHERE MATCH(First, Last) AGAINST('+Jon' IN BOOLEAN MODE)
ORDER BY score DESC;

Note: Give attention to the + operator. This one is only available in BOOLEAN MODE.

Why I suggest NATURAL MODE for sorting by relevance is that it returns for Jon Chris:

Jon Chris        | Jonas
Jon Martin Chris | Jonas

And BOOLEAN MODE could return for +Jon +Chris:

Jon Martin Chris | Jonas
Jon Chris        | Jonas

This is because both words are found in BOOLEAN MODE returning the score 2, but NATURAL MODE adds more for the first entry because its a direct hit and/or direct following words returning the better search result.

我早已燃尽 2024-11-25 03:48:22

分数可能始终为 1(或 0)的另一个原因是全文索引是否发生了多次更改:运行 OPTIMIZE TABLE my_table 将修复此类降级索引,如 微调中所述全文搜索页面。

Another reason the score may always be 1 (or 0) is if the full-text indexes have suffered many changes: running OPTIMIZE TABLE my_table will fix such degraded indexes, as documented in the Fine-tuning Full-text Search pages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文