lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.64k stars 133 forks source link

[Suggestion] Async version of .LoadJSON()? #261

Closed scambier closed 3 months ago

scambier commented 3 months ago

Hello :)

I'm using MiniSearch for my Obsidian plugin Omnisearch. It works wonderfully (thank you!), but for a certain category of users with literally thousands of documents, the .LoadJSON() function takes a long time - often more than 10 seconds! - during which the main thread is totally blocked.

I experimented a bit and wrote an async version of this function. The load time is obviously a bit longer, but the user experience is, in my opinion, greatly improved.

Now I understand that supporting large indexes is a non-goal of MiniSearch, buuuuuuut.... 😁 what do you think?

lucaong commented 3 months ago

Hi @scambier , that's a good idea. I would support an async version of loadJSON for these cases. Your version looks great, I would just look for chances to reduce duplication a bit by factoring out the common part between loadJS and loadJSAsync. I could work on this soon, or alternatively if you want you can send a pull request.

Thank you for the good idea :)

scambier commented 3 months ago

Here it is :)

I did my best to dedupe the code, but the await in a inner loop prevented me to do it as cleanly as I would have liked.

scambier commented 3 months ago

Thanks for the merge 🎉

lucaong commented 3 months ago

Thank you for the contribution! I will soon publish a new release