It’s very efficient to look up something with a query like this:
Get(Ref(Collection("Recipe"), id))
A problem arises when using NextJS with dynamic routing.
For example, here’s a URL: https://www.myapp/recipes/tomahto/oven-cooked-bacon
Note that there is no Ref in the URL, and as such I’ve got no way to use the super efficient query above.
Now I could, but I’m trying to avoid it, make the URL like this: https://www.myapp/recipes/123456789098765432/oven-cooked-bacon
, with that number being the the document Ref, and that would allow me to use the super efficient query.
For the record, I’m trying to avoid it purely for cosmetic reasons.
What I’ve been doing is using Match in a query against an index where values
“data.author” and “data.slug” are being searched against “tomahto” and “oven-cooked-bacon” in the above URL.
Map(
Filter(
Paginate(Match(Index("recipe_by_author_asc_slug_asc")), {
size: 500,
}),
(author, slug, ref) =>
And(
Equals(
Casefold(author),
Casefold(searchAuthor)
),
Equals(Casefold(slug), Casefold(searchSlug))
)
),
(author, slug, ref) => Get(ref)
)
);
I had thought this to be efficient, but I realize now that a scan is being performed. This crystallized when I exceeded the default (64, I believe) of the pagination size option and I got zero results because the document I was searching for was not in the first page of data.
So here’s my question:
Is there any way to perform a query (i.e. search) against an index that does not involve a scan of the entire index (which pretty much the entire collection), or without the Ref will I always be performing a scan?
Thanks in advance for any advice on this.