olivernn / lunr.js

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

how to asynchronous? (avoid block) #459

Closed hoogw closed 4 years ago

hoogw commented 4 years ago

I have very large static json data (150k count)

When I initially create index, it block the browser UI, not responsive, until indexing completed.

Ideally I am ok with long time it took for indexing, as long as it NOT block UI.

I know if I indexing in web worker, it will not block main thread UI.

Can we make lunr.js as asynchronous? like ajax calls, when I indexing, it runs but not block UI, browser keep responsive on other UI task.

olivernn commented 4 years ago

First, you should probably look into pre-building your indexes if the content is relatively static.

It isn't possible to make Lunr indexing asynchronous, it is compute bound and JavaScript is single threaded. If you must build the index in the browser and you don't want to block the UI thread then, as you mention, the indexing needs to be moved off the main thread using WebWorkers or similar.