Removing items by id
See original GitHub issueI’ve got documents that look like this:
const tasks = [
{ id: 1, title: "clean the house" },
{ id: 2, title: "eat food" }
]
If the title of the task with id = 1
changes, I’d like to update that change in the index. However, in my current application, I don’t have access to the entire old version of the document. I just know the id
and the new values for the title field.
In order to remove an item in Minisearch, it looks like I need to pass the whole document that I originally added. Is there a way I can remove an item by id
? If so, I can just remove by id
and then add the new document.
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
Remove element by id - javascript - Stack Overflow
Running this in the chrome console only seems to delete one element at a time when using document.getElementsByClassName("my-elements").remove ...
Read more >Remove element by id in JavaScript? - Tutorialspoint
To remove element by id, you can use remove(). Example. Following is the code − <!DOCTYPE html> <html lang="en"> <head> <meta ...
Read more >Element.remove() - Web APIs - MDN Web Docs
The Element.remove() method removes the element from the DOM.
Read more >How to Remove an Element From an Array by ID in JavaScript
To remove an element from an array by ID in JavaScript, use the findIndex() method to find the index of the object with...
Read more >How To Remove Element By Id In Javascript - Detailed Guide
You can remove element by Id in javascript using the document.getelementbyid("element_id").remove() method. In this tutorial, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for the detailed help and explanation of why this isn’t supported. Your decision making makes total sense to me. I’m happy to implement this within my application in order support removals, I was just avoiding it incase there was a way to remove items by
id
.Thank you for building this awesome library. Before I implemented minisearch, I experimented with fuse, lunr and flexsearch. Minisearch had the best documentation and the it’s search UX felt like it worked nicely out of the box, like a user would expect in most web apps. I found the rest of libraries to be very academic (lunr), hard to get started with (flexsearch), or slow (fuse). Thank you!
@mashpie @clibu @lukevp @rfox12 @priyadarshy I revive this old thread to announce that the newly released
v6.0.0-beta.1
(soon to bev6.0.0
) includes a new methoddiscard
(and related methodsdiscardAll
andreplace
) which removes a document by ID.The reasons given in this thread for why
remove
takes a full document are still valid, butdiscard
takes a different approach, made possible by the internal design ofMiniSearch
. Instead of immediately removing a document from the index (which would only be feasible given the original document),discard
marks the current document version as discarded, so it is immediately ignored by searches, but does not mutate the index. Instead, that is left to a vacuuming process, ran by default after a certain number of documents are discarded. Vacuuming traverses the index and removes references to discarded documents, allowing memory to be released. See the documentation here: https://lucaong.github.io/minisearch/classes/_minisearch_.minisearch.html#discardThis provides the feature requested by this issue, while avoiding the drawbacks of a naive implementation: the original documents are not stored, and use cases that do not need to remove documents incur no overhead.