I have a collection of documents in Firestore which has a field which is an array of strings, these are tags that have been added to the data.
The user can filter the data by selecting and deselecting these tags on the frontend so I'm doing an array-contains-any to query Firestore.
I then score the results on best match, so documents that match more tags are sorted to the top and displayed to the top of the page for the user.
I'm now trying to paginate this data, using a startAfter with a document snapshot as the cursor and a limit. But I need to ensure that higher scoring documents are not excluded when the limit does not extend to that document in the default ordering (ascending by id). I am not ordering the results set in any specific way as it is.
My question is, is there any way to query Firestore in such a way that it can order the results of the query by the most tags that match in the array-contains-any query, or if not, how can i change my data model/logic to do this in a way that will scale.
Querying the entire dataset and implementing the pagination myself does not seem like the most practical solution.