小编Cor*_*bin的帖子

为什么 lunr 不会索引 JSON 数组中的多个单词字符串?

Lunr 在查找大多数结果方面做得很好,但我不明白为什么它不会返回包含在 JSON 数组中的多字字符串。

这是一个示例 JSON 文件,用于了解我的数据的结构:

[{
    "title": "Rolling Loud",
    "date": "May 5–7",
    "location": "Miami, FL, USA",
    "rock-artists": [],
    "hh-artists": ["Kendrick Lamar", "Future"],
    "electronic-artists": [],
    "other-artists": []
}]
Run Code Online (Sandbox Code Playgroud)

当我搜索“Miami”和“Future”时,lunr 返回了节日。但是,在搜索“Kendrick”或“Kendrick Lamar”时,lunr 不会返回节日。

相关代码:

// initialize lunr
var idx = lunr(function () {
    this.field('id');
    this.field('title', { boost: 3 });
    this.field('date');
    this.field('location');
    this.field('rockArtists', { boost: 3 });
    this.field('hhArtists', { boost: 3 });
    this.field('electronicArtists', { boost: 3 });
    this.field('otherArtists', { boost: 3 });

    // add festivals to lunr
    for (var key in …
Run Code Online (Sandbox Code Playgroud)

javascript json lunrjs

0
推荐指数
1
解决办法
838
查看次数

标签 统计

javascript ×1

json ×1

lunrjs ×1