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.

去到頂部