I have this relatively complex search query that's already being built for the purposes of my application by my backend API.
Now, I want to implement additional functionality on top of it, which would allow to supply an array of IDs of documents that'd be boosted up in the search results in the provided order.
For example, if an emtpy match
query would give a result like:
[{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, ...]
Then what I'd want to do is basically to provide a [3, 4, 5]
which would then transform the result into:
[{id: 3}, {id: 4}, {id: 5}, {id: 1}, {id: 2}, ...]
My current idea is to use mget
(since, IIRC, it preserves the requested document order), exclude the documents from the main query and then merge the results. Of course then I'd need to have the pagination functionality preserved, which implies a need for some additional, 'hacky' code (checking if the offset is bigger than the length of the provided array of id and truncate the array if it is lower, etc.).
Is there a better way I can achieve this? Appreciate any advice. Thanks.