Socket
Socket
Sign inDemoInstall

lunr

Package Overview
Dependencies
0
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lunr

Simple full-text search in your browser.


Version published
Weekly downloads
2.1M
decreased by-0.28%
Maintainers
1
Install size
2.13 MB
Created
Weekly downloads
 

Package description

What is lunr?

The lunr npm package is a small, full-text search library for use in a web browser or Node.js environment. It provides a simple search interface for retrieving documents based on a search query. Lunr is designed to be easy to set up and use, without the need for a dedicated backend search server.

What are lunr's main functionalities?

Creating an index

This code sample demonstrates how to create a search index with lunr. Fields to be indexed are specified, and documents are added to the index.

const lunr = require('lunr');
const idx = lunr(function () {
  this.field('title');
  this.field('body');
  this.add({
    'title': 'Example',
    'body': 'This is an example.'
  });
});

Searching the index

Once an index has been created, you can search it using a query string. This code sample searches for the term 'example' in the index.

const results = idx.search('example');

Serializing and loading an index

Lunr allows you to serialize an index to JSON and load it back. This is useful for saving the index to disk or sending it over the network.

const serializedIndex = JSON.stringify(idx);
const loadedIndex = lunr.Index.load(JSON.parse(serializedIndex));

Other packages similar to lunr

Changelog

Source

0.3.3

  • Fix bug #32 which prevented lunr being used where a console object is not present, thanks Tony Marklove and wyuenho

Readme

Source

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', { boost: 10 })
    this.field('body')
})

Adding documents to be indexed is as simple as:

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)

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:

[{
    "ref": 1,
    "score": 0.87533
}]

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.

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.

Contributing

Contributions are very welcome, to make the process as easy as possible please follow these steps:

  • Open an issue detailing the bug you've found, or the feature you wish to add. Simplified working examples using something like jsFiddle make it easier to diagnose your problem.
  • Add tests for your code (so I don't accidentally break it in the future)
  • Don't change version numbers or make new builds as part of your changes

Developer Dependencies

A JavaScript runtime is required for building the library.

Run the tests with, this will use phantomjs to run the tests:

make test

The tests can also be run in the browser by starting the test server:

make test_server

This will start a server on port 3000, the tests are then available at '/test'

Keywords

FAQs

Last updated on 30 May 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc