闲萝卜

懒人画画
懒人✍️
猫奴

JavaScript全文搜索引擎:lunr.js


为您的客户端应用程序提供一个简单的全文搜索引擎。类似 Solr。示例代码:
官网(下载地址)https://lunrjs.com/

//定义索引
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
}]

评论

© 闲萝卜 | Powered by LOFTER