How can I generate a scoped search key that limits...
# community-help
g
How can I generate a scoped search key that limits searching to a specific collection? There's no
collection
parameter in
generateScopedSearchKey()
.
k
Use the parent API key to enforce collection limit.
g
How do I do that?
Found it
k
Yes
g
Another issue here. The preset contains
per_page: 3
, but the logged result contains 10 items.
Also, there's
collection: users
in the preset, but I can still search on any collection if I try.
By the documentation, it seems I should be able to limit the collection in the preset.
k
there's
collection: users
in the preset, but I can still search on any collection if I try.
Does the parent API key of the scoped API key restrict to users collection?
g
No, but if the restriction comes from the parent API key, why does the documentation show the parameter
collection
passed in the preset creation request? Does it serve a different purpose?
k
Preset is just a way for you to store and refer to search params without needing to send them for every search request. If you also pass an explicit collection param in the request, that takes precedence over the preset config.
g
Got it, but what about the
per_page
? The preset sets it to
3
and I'm not passing another value explicitly. Why is it being set to the default
10
anyway?
k
I'm just trying to reproduce this but I'm not able to. Can you post a full snippet? For e..g. here's what I tried: https://gist.github.com/kishorenc/126ae6d3753f3c4441df52b82462ebd4
g
Maybe it's an issue in the JS SDK, I'll write a repro
No, wait, the preset works when I pass it directly to the search. What doesn't work is the embedded preset in the scoped key.
You can see in the attached screenshot here that I'm embedding the preset in the scoped key and then I just use the key, without explicitly passing the preset to the search function. https://typesense-community.slack.com/archives/C01P749MET0/p1686666301585319?thread_ts=1686665613.494379&cid=C01P749MET0
k
Let me get back to you on this.
👍 1