Socket
Socket
Sign inDemoInstall

lunr

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lunr

Simple full-text search in your browser.


Version published
Weekly downloads
2.3M
decreased by-2.15%
Maintainers
1
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 10 May 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc