Git Product home page Git Product logo

lunr-mutable-indexes's Introduction

Lunr Mutable Indexes - Mutable indexes for lunr.js 2.1.x

With the release of lunr.js 2.0, lunr removed the ability to update existing indexes with new data. While the space benefits of this change are nice, some users need the flexibility of updating their indexes with new data. That's what this library is for.

Example

A simple search index can be created with the familiar lunr syntax; just substitute lunr-mutable for lunr.

var lunrMutable = require('lunr-mutable-indexes');

var index = lunrMutable(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"
  })
})

Now, with a mutable index, we can add...

index.add({
    "title": "Merchant of Venice",
    "body": "You speak an infinite deal of nothing.",
    "author": "William Shakespeare",
    "id": "2"
});

Remove...

index.remove({ id: "1" });

Or update existing documents.

index.update({
    "body": "With mirth and laughter let old wrinkles come.",
    "id": "2"
});

Index serialization also works, with the Index namespace accessible through the lunr-mutable-indexes object.

// Serialize an index:
var serialized = JSON.stringify(index);

// ...and deserialize it later:
var sameIndex = lunrMutable.Index.load(JSON.parse(serialized));

Caveats

The main tradeoffs with lunr-mutable-index were originally discussed in this PR in lunr.

  • Mutable indexes work by having a handle to their original builder - this inflates the index size a bit.
  • Changing a builder's tokenizer won't persist across serialization boundaries.
  • Gaps in builder.termIndex may build up when documents are deleted.
  • The index is completely rebuilt when a document is added/updated/removed

Work is ongoing to make improvements with these potential drawbacks, but please feel free to contribute fixes!

Thanks

I wrote a simple extension to lunr.js - I would like to thank the following people for helping to make my life easier:

  • Oliver Nightingale (@olivernn) for writing lunr.js in the first place!
  • John Kupko (@k00p) for making the library easier to use and helping with some of the NPM plumbing!

lunr-mutable-indexes's People

Contributors

hoelzro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lunr-mutable-indexes's Issues

Use in the browser

Hello,

I was wondering if there was a way I could use this package in the browser.

Thanks!

lunr.Pipeline.registerFunction undefined

@hoelzro Awesome project!

I was trying to get this working with multi-language support with:
https://github.com/MihaiValentin/lunr-languages

And i'm hitting this error:

TypeError: Cannot read property 'registerFunction' of undefined
at */node_modules/lunr-languages/lunr.es.js:77:18

it fails here lunr.Pipeline.registerFunction(lunr.es.trimmer, 'trimmer-es');
I've digged a bit into your code, but haven't been able to find how fix this.

Any ideas / tips how to get this working?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.