Closed kozi closed 2 years ago
Hi @kozi , that's a good question, and a common need in search applications.
The reason why such option is not provided inside MiniSearch is that the algorithm cannot really do that more efficiently than collecting all results first, then truncating the list to the first N. That's because the relevance score can only be calculated at runtime for a given search, so the algorithm must first retrieve and score all matching results, then sort them by score, and only after it could truncate the list. In other words, the relevance score of a document depends on the specific search, so it is not possible to retrieve documents from the index already in order of decreasing score.
In sum, a limit
option limiting the results to the top N could be implemented, but MiniSearch would do that by truncating the result set, no differently than how it can be done in user code.
Hi @kozi , I will close the issue for now, as I think my reply answers it, but feel free to comment further if necessary, and in case I can reopen it.
Is there a way to specify a maximum number of hits? I can of course truncate the result set but the search algorithm could possibly stop earlier if N hits were found, right?