# lunr

返回:大前端开源

# 简单示例

var idx = lunr(function() {
  this.field("title");
  this.field("body");

  this.add({
    title: "Twelfth-Night",
    body: "If music be the food of love, play on: Give me excess of it…",
    author: "William Shakespeare",
    id: "1",
  });
});
1
2
3
4
5
6
7
8
9
10
11

然后再像下面这样

idx.search("love");
1

这将返回一个匹配文档列表,其中包含与搜索查询的匹配程度以及与该匹配相关的任何关联元数据的分数:

[
  {
    ref: "1",
    score: 0.3535533905932737,
    matchData: {
      metadata: {
        love: {
          body: {},
        },
      },
    },
  },
];
1
2
3
4
5
6
7
8
9
10
11
12
13

# 安装

只需在要使用它的页面中包含 lunr.js 源文件。所有现代浏览器均支持 Lunr.js。

npm install lunr
1