lunr.jsJavaScript 搜索引擎

联合创作 · 2023-09-29 04:00

lunr.js 实现了在网页上的搜索引擎,类似 Solr


示例代码:



//定义索引
var idx = lunr(function () {
this.field('title', { boost: 10 })
this.field('body')
})

//添加索引
var doc = {
"title": "Twelfth-Night",
"body": "If music be the food of love, play on: Give me excess of it…",
"author": "William Shakespeare",
"id": 1
}
idx.add(doc)

//搜索
idx.search("love")

//返回结果
[{
"ref": 1,
"score": 0.87533
}]

 

浏览 22
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报