使用 xaamp v8.1.10 中的 mysql 以及 laravel v5.5.3.
在表'ex1'中为'des'和'ft_min_word_len = 1'.启用全文搜索索引
laravel 查询:
$string='pink item product;
$result = ex::active()->selectRaw("*,match(des) against('$string' in boolean mode) as relevance")->whereRaw("match(des) against('$string' in boolean mode)")->orderBy('relevance', 'desc')->get();
我得到的结果是
(结果被截断)
id | 相关性 | des |
---|---|---|
64 | 1.3543391227722 | 令人惊叹的粉色小巧蕾丝单品。 |
182 | 1.3543391227722 | 这件粉色高涤纶单品是单品。 |
598 | 1.3543391227722 | 粉色大涤纶单品是哪款。 |
653 | 1.3543391227722 | 令人惊叹的粉色加大码亚麻单品。 |
808 | 1.3543391227722 | 粉色高羊绒单品是什么单品 |
19 | 1.344024181366 | 不同的粉红色大丝绸产品是项目。 |
134 | 1.344024181366 | 粉红色大羊毛产品是项目。 |
140 | 1.344024181366 | 这款粉红色高蕾丝产品是产品。 |
233 | 1.344024181366 | 新款粉色超小蕾丝单品上架 |
273 | 1.344024181366 | 这件粉色高羊绒单品是产品。 |
625 | 1.344024181366 | 令人惊叹的粉色中号蕾丝产品是商品。 |
893 | 1.344024181366 | 粉红色超小皮件是产品。 |
908 | 1.344024181366 | 粉红色高蕾丝产品是哪个项目。 |
992 | 1.344024181366 | 这款粉红色的大棉产品是item. |
21 | 1.3337094783783 | 粉色特小羊绒产品是产品 |
我的问题是:
id | 相关性 | des |
---|---|---|
64 | 1.3543391227722 | 令人惊叹的粉色小巧蕾丝单品。 |
21 | 1.3337094783783 | 粉色小羊绒产品就是产品 |
尽管出现次数相同:
第 64 列有:item-2 次,pink-1 次,第 21 列有:product-2 次 pink-1 次。
我以为计算是这样的:
(来自 MySQL FUll Text Search Doc 的参考,它说:)
${rank} = ${TF} * ${IDF} * ${IDF} + ${TF} * ${IDF} * ${IDF}
SELECT (1*log10(8/6)*log10(8/6)) + (2*log10(8/2)*log10(8/2));
这是:
(number of occurences of word 1* log10(total records in table/total matching records where the word is found) + (number of occurences of word 2* log10(total records in table/total matching records where the word is found) + ... + (number of occurences of word n * log10(total records in table/total matching records where the word n is found)
此外,即使第 64 列和第 182 列具有相同的出现集,都有 pink-1 时间和 item-2 时间,但第 64 列的相关性更高。为什么?
最初我虽然这是基于数据库中的行号,它的创建顺序。但在那种情况下,我的第一个问题应该是无效的,因为第 21 列应该在第 64 列之前。我不明白它是如何计算的。
到目前为止,我在全文搜索中使用 MySQL 文档进行了计算,但我找不到涵盖这种情况的文档。
提前致谢。