【发布时间】:2017-09-21 00:30:08
【问题描述】:
我在网络浏览器中使用lunr (elastic lunr0.9.5) 作为搜索引擎。
它既简单又非常快。但是当它有更多时,它不会在第一个位置列出完全匹配的对象。
我在 Typescript 中的 lunr 配置
this.lunrIndex = lunr(function () {
this.field('itemId');
this.field('name');
this.ref('itemId');
this.pipeline.remove(lunr.stemmer)
})
当我搜索 pan d ca 文本时,它正在返回,
[{
"ref": "PANCOR DSR CAPSULE 10''S",
"score": 0.01674628244112235
},
{
"ref": "PANLID DSR CAPSULE 10''S",
"score": 0.01674628244112235
},
{
"ref": "PANSIO DSR CAPSULE 10''S",
"score": 0.01590146213665648
},
{
"ref": "PANLIFE DSR CAPSULE 10''S",
"score": 0.015507241586286287
},
{
"ref": "PANSEC DSR CAPSULE 10''S",
"score": 0.014526355502926632
},
{
"ref": "PAN D CAPSULE 10''S",
"score": 0.011554433713104873
}
]
Lunr 修剪可能是上述结果的原因之一,所以我从其管道执行中删除了lunr.trimmer,但它仍然给出相同的结果。
以上结果显示,完全匹配字符串(PAN D C) 得分较低(0.011554433713104873)。我错过了这里的任何配置吗?
我需要精确匹配的字符串应该比其他字符串获得最高分,我该如何实现?
【问题讨论】:
-
您使用的是 lunr 还是 elasticlunr(它们是不同的库)?
-
抱歉给您带来了困惑 :-( 我正在使用 lunr。
-
Elastic lunr 建立在 lunr 之上,两者差别不大
-
elasticlunr 是/曾经是 lunr 的一个分支,但它们已经出现了很大的分歧。
标签: javascript json lunrjs