elasticlunr vs flexsearch vs fuse.js vs js-search vs lunr vs search-index
JavaScript Search Libraries
elasticlunrflexsearchfuse.jsjs-searchlunrsearch-indexSimilar Packages:

JavaScript Search Libraries

JavaScript search libraries are designed to provide efficient and flexible search capabilities within web applications. They allow developers to implement full-text search functionality, enabling users to quickly find relevant information from large datasets. These libraries vary in terms of features, performance, and ease of use, making it essential to choose the right one based on specific project requirements.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
elasticlunr02,070-7710 years agoMIT
flexsearch013,6812.33 MB308 months agoApache-2.0
fuse.js020,215312 kB224 days agoApache-2.0
js-search02,225117 kB83 years agoMIT
lunr09,207-1296 years agoMIT
search-index01,425693 kB5a year agoMIT

Feature Comparison: elasticlunr vs flexsearch vs fuse.js vs js-search vs lunr vs search-index

Search Algorithm

  • elasticlunr:

    ElasticLunr uses a simple inverted index structure to provide fast search capabilities. It mimics Elasticsearch's functionality, allowing for efficient querying and scoring of results based on term frequency and document frequency.

  • flexsearch:

    FlexSearch employs a highly optimized algorithm that combines various techniques like tokenization, indexing, and scoring to deliver lightning-fast search results, even with large datasets. It supports advanced features like multi-language indexing and custom scoring functions.

  • fuse.js:

    Fuse.js implements a fuzzy search algorithm that allows for approximate matching, making it resilient to user input errors. It uses a scoring system to rank results based on their relevance to the search query, enhancing user experience.

  • js-search:

    js-search utilizes a basic linear search algorithm, which is straightforward but may not be as efficient for larger datasets. It indexes data in a simple way, making it easy to understand but potentially slower compared to more advanced libraries.

  • lunr:

    Lunr creates an inverted index for efficient full-text search. It allows for complex queries and supports features like stemming and scoring, providing a good balance between performance and functionality for static sites.

  • search-index:

    Search Index combines various indexing techniques to provide real-time search capabilities. It supports complex queries and updates, making it suitable for applications that require dynamic data handling.

Ease of Use

  • elasticlunr:

    ElasticLunr is designed for simplicity and ease of integration. Its API is intuitive, making it easy for developers to implement search functionality without extensive configuration or setup.

  • flexsearch:

    FlexSearch, while powerful, may require a bit more understanding of its advanced features. However, its documentation is comprehensive, helping developers get started quickly with performance optimization in mind.

  • fuse.js:

    Fuse.js is very user-friendly, with a straightforward API that allows developers to implement fuzzy search with minimal effort. Its configuration options are clear, making it easy to customize search behavior.

  • js-search:

    js-search is extremely easy to use, with a simple API that allows for quick setup. It's ideal for developers looking for a no-fuss search solution without advanced features.

  • lunr:

    Lunr is relatively easy to use, with clear documentation and examples. It provides a good balance of features without overwhelming complexity, making it accessible for most developers.

  • search-index:

    Search Index may have a steeper learning curve due to its advanced features and configurations. However, its flexibility and power make it worthwhile for complex applications.

Performance

  • elasticlunr:

    ElasticLunr performs well for small to medium datasets, but may experience slower performance with larger datasets due to its reliance on client-side processing and indexing.

  • flexsearch:

    FlexSearch is optimized for speed, capable of handling large datasets efficiently. Its performance is one of its key strengths, making it suitable for applications requiring quick search responses.

  • fuse.js:

    Fuse.js performs well for small to medium datasets, but its fuzzy search capabilities can introduce some performance overhead. It's best suited for applications where user input may vary significantly.

  • js-search:

    js-search may not be the fastest option for large datasets due to its linear search approach. It's best for smaller datasets where simplicity and ease of use are prioritized over speed.

  • lunr:

    Lunr provides good performance for static sites and smaller datasets. However, it may not scale as well with very large datasets compared to more optimized libraries.

  • search-index:

    Search Index is designed for performance, supporting real-time updates and complex queries efficiently. It's suitable for applications that require fast and responsive search capabilities.

Indexing Capabilities

  • elasticlunr:

    ElasticLunr allows for easy indexing of documents with a straightforward API. It supports basic indexing features but may lack some advanced capabilities found in server-side solutions.

  • flexsearch:

    FlexSearch offers advanced indexing capabilities, including multi-language support and customizable tokenization. It allows for efficient indexing of large datasets with minimal configuration.

  • fuse.js:

    Fuse.js requires a manual setup for indexing, but it provides flexibility in how data is indexed. It's suitable for applications where developers want control over the indexing process.

  • js-search:

    js-search provides basic indexing capabilities, making it easy to set up but lacking in advanced features. It's best for simple use cases where complex indexing is not required.

  • lunr:

    Lunr supports full-text indexing and provides features like stemming and stop word filtering. It's effective for static sites needing robust search capabilities without server-side dependencies.

  • search-index:

    Search Index offers advanced indexing features, including real-time updates and complex query handling. It's suitable for applications that require dynamic data indexing and search capabilities.

Community and Support

  • elasticlunr:

    ElasticLunr has a growing community and decent documentation, providing enough resources for developers to get started and troubleshoot common issues.

  • flexsearch:

    FlexSearch has an active community and comprehensive documentation, making it easy for developers to find support and examples for implementation.

  • fuse.js:

    Fuse.js benefits from a strong community and extensive documentation, with many examples available to help developers understand its fuzzy search capabilities.

  • js-search:

    js-search has a smaller community but offers basic documentation. It may not have as many resources available compared to more popular libraries.

  • lunr:

    Lunr has a well-established community and good documentation, making it easy for developers to find help and resources for implementation.

  • search-index:

    Search Index has a growing community, and while its documentation is improving, it may still have gaps compared to more established libraries.

How to Choose: elasticlunr vs flexsearch vs fuse.js vs js-search vs lunr vs search-index

  • elasticlunr:

    Choose ElasticLunr if you need a lightweight, client-side search solution that mimics Elasticsearch's API. It's ideal for small to medium datasets and provides a simple setup with minimal configuration.

  • flexsearch:

    Opt for FlexSearch when performance is a top priority, especially for large datasets. It offers highly optimized search capabilities with features like scoring and multi-language support, making it suitable for applications requiring fast and accurate search results.

  • fuse.js:

    Select Fuse.js for its fuzzy search capabilities, which allow for typo tolerance and approximate matching. It's perfect for applications where users may not know the exact terms they are searching for, enhancing user experience with intelligent search results.

  • js-search:

    Use js-search if you prefer a straightforward, easy-to-understand implementation. It provides basic search functionality and is suitable for smaller projects or when simplicity is key without the need for advanced features.

  • lunr:

    Choose Lunr if you want a full-text search engine that is easy to integrate and provides a good balance between performance and features. It's great for static sites and offers indexing capabilities without requiring a server-side component.

  • search-index:

    Select Search Index for a more complex search solution that supports both client and server-side environments. It's suitable for applications needing advanced indexing and search features, such as real-time updates and complex queries.

README for elasticlunr

Elasticlunr.js

Build Status npm version GitHub license

Elasticlunr.js is a lightweight full-text search engine developed in JavaScript for browser search and offline search. Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time boosting, field search, more rational scoring/ranking methodology, fast computation speed and so on. Elasticlunr.js is a bit like Solr, but much smaller and not as bright, but also provide flexible configuration, query-time boosting, field search and other features.

Why You Need Lightweight Offline Search?

  1. In some system, you don't want to deploy any complex full-text search engine(such as Lucence, Elasticsearch, Sphinx, etc.), you only want to provide some static web pages and provide search functionality , then you could build index in previous and load index in client side(such as Browser).
  2. Provide offline search functionality. For some documents, user usually download these documents, you could build index and put index in the documents package, then provide offline search functionality.
  3. For some limited or restricted network, such WAN or LAN, offline search is a better choice.
  4. For mobile device, Iphone or Android phone, network traffic maybe very expensive, then provide offline search is a good choice.
  5. If you want to provide search functionality in your Node.js system, and you don't want to use a complex system, or you only need to support thousands of documents, then Elasticlunr.js is what you want to use.

Key Features Comparing with Lunr.js

  1. Query-Time Boosting, you don't need to setup boosting weight in index building procedure, Query-Time Boosting make it more flexible that you could try different boosting scheme.
  2. More Rational Scoring Mechanism, Elasticlunr.js use quite the same scoring mechanism as Elasticsearch, and also this scoring mechanism is used by lucene.
  3. Field-Search, you could choose which field to index and which field to search.
  4. Boolean Model, you could set which field to search and the boolean model for each query token, such as "OR", "AND".
  5. Combined Boolean Model, TF/IDF Model and the Vector Space Model, make the results ranking more reliable.
  6. Fast, Elasticlunr.js removed TokenCorpus and Vector from lunr.js, by using combined model there is no need to compute the vector of a document and query string to compute similarity of query and matched document, this improve the search speed significantly.
  7. Small Index Size, Elasticlunr.js did not store TokenCorpus because there is no need to compute query vector and document vector, then the index file is small, and also user could choose if they need to store the origianl JSON doc, if user care more about the index size, they could choose not store the original JSON doc, this could reduce the index size significantly. This is especially helpful when elasticlunr.js is used as offline search. The index size is about half size of lunr.js index file.

Example

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

var index = elasticlunr(function () {
    this.addField('title');
    this.addField('body');
    this.setRef('id');
});

Adding documents to the index is as simple as:

var doc1 = {
    "id": 1,
    "title": "Oracle released its latest database Oracle 12g",
    "body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}

var doc2 = {
    "id": 2,
    "title": "Oracle released its profit report of 2015",
    "body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}

index.addDoc(doc1);
index.addDoc(doc2);

Then searching is as simple:

index.search("Oracle database profit");

Also, you could do query-time boosting by passing in a configuration.

index.search("Oracle database profit", {
    fields: {
        title: {boost: 2},
        body: {boost: 1}
    }
});

This returns a list of matching documents with a score of how closely they match the search query:

[{
    "ref": 1,
    "score": 0.5376053707962494
},
{
    "ref": 2,
    "score": 0.5237481076838757
}]

If user do not want to store the original JSON documents, they could use the following setting:

var index = elasticlunr(function () {
    this.addField('title');
    this.addField('body');
    this.setRef('id');
    this.saveDocument(false);
});

Then elasticlunr.js will not store the JSON documents, this will reduce the index size, but also bring some inconvenience such as update a document or delete a document by document id or reference. Actually most of the time user will not udpate or delete a document from index.

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

Description

Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time Boosting, Field Search, more rational scoring/ranking methodology, flexible configuration and so on. A bit like Solr, but much smaller and not as bright, but also provide flexible configuration, query-time boosting, field search, etc.

Installation

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

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

Documentation

This part only contain important apects of elasticlunr.js, for the whole documentation, please go to API documentation.

1. Build Index

When you first create a index instance, you need to specify which field you want to index. If you did not specify which field to index, then no field will be searchable for your documents. You could specify fields by:

var index = elasticlunr(function () {
    this.addField('title');
    this.addField('body');
    this.setRef('id');
});

You could also set the document reference by this.setRef('id'), if you did not set document ref, elasticlunr.js will use 'id' as default.

You could do the above index setup as followings:

var index = elasticlunr();
index.addField('title');
index.addField('body');
index.setRef('id');

Also you could choose not store the original JSON document to reduce the index size by:

var index = elasticlunr();
index.addField('title');
index.addField('body');
index.setRef('id');
index.saveDocument(false);

2. Add document to index

Add document to index is very simple, just prepare you document in JSON format, then add it to index.

var doc1 = {
    "id": 1,
    "title": "Oracle released its latest database Oracle 12g",
    "body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}

var doc2 = {
    "id": 2,
    "title": "Oracle released its profit report of 2015",
    "body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}

index.addDoc(doc1);
index.addDoc(doc2);

If your JSON document contains field that not configured in index, then that field will not be indexed, which means that field is not searchable.

3. Remove document from index

Elasticlunr.js support remove a document from index, just provide JSON document to elasticlunr.Index.prototype.removeDoc() function.

For example:

var doc = {
    "id": 1,
    "title": "Oracle released its latest database Oracle 12g",
    "body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}

index.removeDoc(doc);

Remove a document will remove each token of that document's each field from field-specified inverted index.

4. Update a document in index

Elasticlunr.js support update a document in index, just provide JSON document to elasticlunr.Index.prototype.update() function.

For example:

var doc = {
    "id": 1,
    "title": "Oracle released its latest database Oracle 12g",
    "body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}

index.update(doc);

5. Query from Index

Elasticlunr.js provides flexible query configuration, supports query-time boosting and Boolean logic setting. You could setup a configuration tell elasticlunr.js how to do query-time boosting, which field to search in, how to do the boolean logic. Or you could just use it by simply provide a query string, this will aslo works perfectly because the scoring mechanism is very efficient.

5.1 Simple Query

Because elasticlunr.js has a very perfect scoring mechanism, so for most of your requirement, simple search would be easy to meet your requirement.

index.search("Oracle database profit");

Output is a results array, each element of results array is an Object contain a ref field and a score field. ref is the document reference. score is the similarity measurement.

Results array is sorted descent by score.

5.2 Configuration Query

5.2.1 Query-Time Boosting

Setup which fields to search in by passing in a JSON configuration, and setup boosting for each search field. If you setup this configuration, then elasticlunr.js will only search the query string in the specified fields with boosting weight.

The scoring mechanism used in elasticlunr.js is very complex, please goto details for more information.

index.search("Oracle database profit", {
    fields: {
        title: {boost: 2},
        body: {boost: 1}
    }
});

5.2.2 Boolean Model

Elasticlunr.js also support boolean logic setting, if no boolean logic is setted, elasticlunr.js use "OR" logic defaulty. By "OR" default logic, elasticlunr.js could reach a high Recall.

index.search("Oracle database profit", {
    fields: {
        title: {boost: 2},
        body: {boost: 1}
    },
    bool: "OR"
});

Boolean model could be setted by global level such as the above setting or it could be setted by field level, if both global and field level contains a "bool" setting, field level setting will overwrite the global setting.

index.search("Oracle database profit", {
    fields: {
        title: {boost: 2, bool: "AND"},
        body: {boost: 1}
    },
    bool: "OR"
});

The above setting will search title field by AND model and other fields by "OR" model. Currently if you search in multiply fields, resutls from each field will be merged together to give the query results. In the future elasticlunr will support configuration that user could set how to combine the results from each field, such as "most_field" or "top_field".

5.2.3 Token Expandation

Sometimes user want to expand a query token to increase RECALL, then user could set expand model to true by configuration, default is false. For example, user query token is "micro", and assume "microwave" and "microscope" are in the index, then is user choose expand the query token "micro" to increase RECALL, both "microwave" and "microscope" will be returned and search in the index. The query results from expanded tokens are penalized because they are not exactly the same as the query token.

index.search("micro", {
    fields: {
        title: {boost: 2, bool: "AND"},
        body: {boost: 1}
    },
    bool: "OR",
    expand: true
});

Field level expand configuration will overwrite global expand configuration.

index.search("micro", {
    fields: {
        title: {
            boost: 2,
            bool: "AND",
            expand: false
        },
        body: {boost: 1}
    },
    bool: "OR",
    expand: true
});

6. Add customized stop words

Elasticlunr.js contains some default stop words of English, such as:

  • a
  • about
  • an
  • all
  • also
  • and
  • any
  • but
  • the
  • ...

Defaultly elasticlunr.js contains 120 stop words, user could decide not use these default stop words or add customized stop words.

6.1 Remove default stop words

You could remove default stop words simply as:

elasticlunr.clearStopWords();

6.2 Add customized stop words

User could add a list of customized stop words.

var customized_stop_words = ['an', 'hello', 'xyzabc'];
elasticlunr.addStopWords(customized_stop_words);

7. Use elasticlunr in Node.js

Elasticlunr support Node.js, you could use elastilunr in node.js as a node-module.

Install elasticlunr by:

npm install elasticlunr

then in your node.js project or in node.js console:

var elasticlunr = require('elasticlunr');

var index = elasticlunr(function () {
    this.addField('title')
    this.addField('body')
});

var doc1 = {
    "id": 1,
    "title": "Oracle released its latest database Oracle 12g",
    "body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}

var doc2 = {
    "id": 2,
    "title": "Oracle released its profit report of 2015",
    "body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}

index.addDoc(doc1);
index.addDoc(doc2);

index.search("Oracle database profit");

Other Languages

Default supported language of elasticlunr.js is English, if you want to use elasticlunr.js to index other language documents, then you need to use elasticlunr.js combined with lunr-languages.

Other languages example in Browser

Suppose you are using elasticlunr.js in browser for other languages, you could download the corresponding language support from lunr-languages, then include the scripts as:

<script src="lunr.stemmer.support.js"></script>
<script src="lunr.de.js"></script>

then, you could use elasticlunr.js as normal:

var index = elasticlunr(function () {
    // use the language (de)
    this.use(elasticlunr.de);
    // then, the normal elasticlunr index initialization
    this.addField('title')
    this.addField('body')
});

Pay attention to the special code:

    this.use(elasticlunr.de);

If you are using other language, such as es(Spanish), download the corresponding lunr.es.js file and lunr.stemmer.support.js, and change the above line to:

    this.use(elasticlunr.es);

Other languages example in Node.js

Suppose you are using elasticlunr.js in Node.js for other languages, you could download the corresponding language support from lunr-languages, put the files lunr.es.js file and lunr.stemmer.support.js in your project, then in your Node.js module, use elasticlunr.js as:

var elasticlunr = require('elasticlunr');
require('./lunr.stemmer.support.js')(elasticlunr);
require('./lunr.de.js')(elasticlunr);

var index = elasticlunr(function () {
    // use the language (de)
    this.use(elasticlunr.de);
    // then, the normal elasticlunr index initialization
    this.addField('title')
    this.addField('body')
});

For more details, please go to lunr-languages.

Contributing

See the CONTRIBUTING.mdown file.