lucaong / minisearch

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

Search inside a worker? #218

Closed remorses closed 1 year ago

remorses commented 1 year ago

Does it make sense to wrap fetching and searching inside a worker?

Did you already do some benchmarks with this approach?

I assume using a worker would not be optimal if there are many results to pass back to the main thread

lucaong commented 1 year ago

@remorses exactly as you say: running indexing and search inside a web worker is possible, but it is a trade off. On one hand, it makes it possible to perform indexing without blocking the main thread, on the other hand it introduces complexity and might make search slower when long result lists have to be exchanged.

My own experience is that for most cases, keeping MiniSearch on the main thread (possibly indexing asynchronously with addAllAsync to avoid blocking) is preferable and more maintainable. I did encounter a couple of cases that were implemented with a web worker, but that’s not how I would generally start.

remorses commented 1 year ago

Thank you for the explanation :)