olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.96k stars 548 forks source link

Is there a way to clear the index? (Removing all docs) #127

Closed sanfilippopablo closed 9 years ago

sanfilippopablo commented 9 years ago

I need this for testing purposes.

olivernn commented 9 years ago

There is no clear method available on index to do this. If you want a fresh index you should just create a new, empty index. Outside of testing purposes I don't really see the need for such a function.

patrickml commented 8 years ago

@olivernn I'm in need of this functionality because we load all documents into memory so they can be searched quickly, but we need a way to update the docs in memory by clearing the indexed data and reloading it.

olivernn commented 8 years ago

@patrickml do you need to update all the documents at once, or individually?

You can update a single document in the index using the lunr.Index.prototype.update method, this actually just removes and then re-adds the document.

If you are doing this in bulk then it really is simpler to just create a whole new index, is there something I missing that means this approach won't work for your use case?