#community-help

Scoped Search Key with Preset Parameters Issue

TLDR Gustavo faces issues with search key generation and preset parameters. Kishore Nallan clarifies how presets work, but the issue remains unresolved, requiring further investigation.

Powered by Struct AI
+11
Jun 13, 2023 (3 months ago)
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:13 PM
How can I generate a scoped search key that limits searching to a specific collection? There's no collection parameter in generateScopedSearchKey().
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:17 PM
Use the parent API key to enforce collection limit.
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:18 PM
How do I do that?
02:19
Gustavo
02:19 PM
Found it
Image 1 for Found it
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:19 PM
Yes
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:25 PM
Another issue here. The preset contains per_page: 3, but the logged result contains 10 items.
Image 1 for Another issue here. The preset contains <code>per_page: 3</code>, but the logged result contains 10 items.Image 2 for Another issue here. The preset contains <code>per_page: 3</code>, but the logged result contains 10 items.
02:26
Gustavo
02:26 PM
Also, there's collection: users in the preset, but I can still search on any collection if I try.
02:27
Gustavo
02:27 PM
By the documentation, it seems I should be able to limit the collection in the preset.
Image 1 for By the documentation, it seems I should be able to limit the collection in the preset.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:30 PM
> 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?
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:33 PM
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?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:45 PM
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.
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:53 PM
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?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:23 PM
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
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
08:07 PM
Maybe it's an issue in the JS SDK, I'll write a repro
08:09
Gustavo
08:09 PM
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.
08:10
Gustavo
08:10 PM
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
Jun 14, 2023 (3 months ago)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:01 PM
Let me get back to you on this.
+11