gpt4 book ai didi

mysql - 针对查询的通配符匹配导致分数 = 0 (php/sql)

转载 作者:行者123 更新时间:2023-11-29 01:04:30 25 4
gpt4 key购买 nike

我正在使用 MySql 5.0.45 版的全文查询,并且我正在尝试根据我的需要对其进行优化。评分系统运行良好,但是因为我现在在输入之前添加了一个词干分析器,所以我不得不在搜索词上使用通配符。问题是现在一个词干词将匹配但返回分数为 0。(即:“restriction”被词干化为“restrict”并且仍然会被识别为匹配但分数为 0)

这是查询:

$escaped_string = mysql_real_escape_string($string);
$query = "SELECT DISTINCT A1.item_ID, item,
4.0 * (match (`item_1`) against ('". $escaped_string."*'))
+ 3.5 * (match (`item_2`) against ('".$escaped_string."*'))
+ 3.0 * (match (`item_3`) against ('".$escaped_string."*'))
+ 2.5 * (match (`item_4`) against ('".$escaped_string."*'))
+ 1.5 * (match (`item_5`) against ('".$escaped_string."*'))
as score
FROM Items A1 LEFT OUTER JOIN Inventory A2 ON A1.item_ID=A2.item_ID
WHERE MATCH(`item_1`, `item_2`,`item_3`,`item_4`,`item_5`) AGAINST ('".$escaped_string."*' IN BOOLEAN MODE)
ORDER BY score DESC
LIMIT 200";

分数在 ('".$escaped_string."')) 之前计算得很好,但在您添加通配符 * 时则不然。在这两种情况下匹配都很好,问题是如果有通配符则不会计算分数。

如有任何帮助,我们将不胜感激! (我希望我做的大部分是对的)

最佳答案

在我看来,您似乎忘记了将 IN BOOLEAN MODE 添加到分数计算中,因为搜索运算符是该模式独有的;如果我明白http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html正确。

我认为以下应该有效:

$escaped_string = mysql_real_escape_string($string);
$query = "SELECT DISTINCT A1.item_ID, item,
4.0 * (match (`item_1`) against ('". $escaped_string."*' IN BOOLEAN MODE))
+ 3.5 * (match (`item_2`) against ('".$escaped_string."*' IN BOOLEAN MODE))
+ 3.0 * (match (`item_3`) against ('".$escaped_string."*' IN BOOLEAN MODE))
+ 2.5 * (match (`item_4`) against ('".$escaped_string."*' IN BOOLEAN MODE))
+ 1.5 * (match (`item_5`) against ('".$escaped_string."*' IN BOOLEAN MODE))
as score
FROM Items A1 LEFT OUTER JOIN Inventory A2 ON A1.item_ID=A2.item_ID
WHERE MATCH(`item_1`, `item_2`,`item_3`,`item_4`,`item_5`) AGAINST ('".$escaped_string."*' IN BOOLEAN MODE)
ORDER BY score DESC
LIMIT 200";

关于mysql - 针对查询的通配符匹配导致分数 = 0 (php/sql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10165181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com