Lunr.js

有点像Solr,但是要小得多但不那么“明亮”。(A bit like Solr, but much smaller and not as bright. )

Github星跟踪图

Lunr.js是一个用于浏览器的小型全文搜索库。 它对JSON文档进行索引,并提供一个简单的搜索界面,用于检索最符合文本查询的文档。

为什么要用?

对于所有数据已经坐在客户端的Web应用程序,能够在客户端上搜索数据也是有道理的。 它可以节省在服务器上添加额外的,压缩的服务。 本地搜索索引将更快,没有网络开销,即使没有网络连接,它仍将可用和易用。

安装
只需在您要使用的页面中包含lunr.js源文件。 所有现代浏览器都支持Lunr.js。
或者,npm包也可用npm安装lunr。
不支持ES5的浏览器将需要一个JavaScript垫片才能使Lunr工作。 您可以使用Augment.js、ES5-Shim或任何修补旧浏览器的库来提供ES5兼容的JavaScript环境。

示例

可以使用以下方法创建一个非常简单的搜索索引:

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"  })})
然后搜索很简单
idx.search("love")

这将返回匹配文档的列表,其匹配搜索查询的匹配程度以及匹配的任何关联元数据的得分:

[  {    "ref": "1",    "score": 0.3535533905932737,    "matchData": {      "metadata": {        "love": {          "body": {}        }      }    }  }]

概览

名称与所有者sunspot/sunspot
主编程语言JavaScript
编程语言Makefile (语言数: 7)
平台
许可证MIT License
发布数83
最新版本名称v2.6.0 (发布于 2022-05-30 10:47:30)
第一版名称v0.0.2 (发布于 )
创建于2008-10-13 15:46:40
推送于2024-03-20 02:35:49
最后一次提交2023-12-28 21:34:03
星数3k
关注者数32
派生数0.9k
提交数2k
已启用问题?
问题数567
打开的问题数145
拉请求数267
打开的拉请求数21
关闭的拉请求数187
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

Lunr.js

Join the chat at https://gitter.im/olivernn/lunr.js

Build Status

A bit like Solr, but much smaller and not as bright.

Example

A very simple search index can be created using the following:

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"
  })
})

Then searching is as simple:

idx.search("love")

This returns a list of matching documents with a score of how closely they match the search query as well as any associated metadata about the match:

[
  {
    "ref": "1",
    "score": 0.3535533905932737,
    "matchData": {
      "metadata": {
        "love": {
          "body": {}
        }
      }
    }
  }
]

API documentation is available, as well as a full working example.

Description

Lunr.js is a small, full-text search library for use in the browser. It indexes JSON documents and provides a simple search interface for retrieving documents that best match text queries.

Why

For web applications with all their data already sitting in the client, it makes sense to be able to search that data on the client too. It saves adding extra, compacted services on the server. A local search index will be quicker, there is no network overhead, and will remain available and useable even without a network connection.

Installation

Simply include the lunr.js source file in the page that you want to use it. Lunr.js is supported in all modern browsers.

Alternatively an npm package is also available npm install lunr.

Browsers that do not support ES5 will require a JavaScript shim for Lunr to work. You can either use Augment.js, ES5-Shim or any library that patches old browsers to provide an ES5 compatible JavaScript environment.

Features

  • Full text search support for 14 languages
  • Boost terms at query time or boost entire documents at index time
  • Scope searches to specific fields
  • Fuzzy term matching with wildcards or edit distance

Contributing

See the CONTRIBUTING.md file.

去到顶部