Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minisearch

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minisearch

Tiny but powerful full-text search engine for browser and Node

  • 3.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
254K
increased by2.88%
Maintainers
1
Weekly downloads
 
Created

What is minisearch?

MiniSearch is a lightweight, full-text search engine for JavaScript. It is designed to be simple to use and efficient, making it suitable for client-side applications as well as server-side usage. MiniSearch allows you to index documents and perform search queries on them, providing features like tokenization, stemming, and field-based search.

What are minisearch's main functionalities?

Indexing Documents

This feature allows you to index a collection of documents. You specify which fields to index and which fields to store in the search results. The `addAll` method is used to add multiple documents to the index.

const MiniSearch = require('minisearch')

let miniSearch = new MiniSearch({
  fields: ['title', 'text'], // fields to index for full-text search
  storeFields: ['title'] // fields to return with search results
})

let documents = [
  { id: 1, title: 'Moby Dick', text: 'Call me Ishmael. Some years ago...' },
  { id: 2, title: 'Pride and Prejudice', text: 'It is a truth universally acknowledged...' },
  // more documents...
]

miniSearch.addAll(documents)

Performing Searches

Once documents are indexed, you can perform search queries on them. The `search` method returns a list of documents that match the query, sorted by relevance.

let results = miniSearch.search('Ishmael')
console.log(results)

Customizing Tokenization

MiniSearch allows you to customize the tokenization process. In this example, the `tokenize` function splits the text into tokens based on whitespace.

let miniSearch = new MiniSearch({
  fields: ['title', 'text'],
  tokenize: (string, _fieldName) => string.split(/\s+/)
})

Stemming and Stop Words

You can also customize how terms are processed and specify stop words. In this example, terms are converted to lowercase, and common stop words are excluded from the index.

let miniSearch = new MiniSearch({
  fields: ['title', 'text'],
  processTerm: (term) => term.toLowerCase(),
  stopWords: new Set(['the', 'is', 'and'])
})

Other packages similar to minisearch

Keywords

FAQs

Package last updated on 24 Nov 2021

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