#community-help

Including All Individual Documents in a Group in Typesense

TLDR Magnus was uncertain how to include all documents within a group in Typesense, and specifically asked about ecommerce product cards. Jason published a new version of Typesense Instantsearch Adapter and advised storing all variant information for a product on each document. Magnus confirmed this as a viable solution.

Powered by Struct AI
9
15mo
Solved
Join the chat
Jun 29, 2022 (15 months ago)
Magnus
Photo of md5-7d2796ababc14477f4c09abc2e8edb05
Magnus
06:44 PM
Hi again. Having a lot of fun with Typesense.

I am playing with group_by and group_limit. I can see the structure for a grouped document is slightly different but was then wondering, if there’s a way to include all of the individual documents that is contained in a group. I know that might sound counter intuitive but would be useful in a case, where you want to show information from the grouped documents. The specific case is this product cards on an ecommerce site. Here’s a screenshot that maybe explains it better:
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:48 PM
Setting group_limit to a large number (even as high as say 10,000) assuming that's the max number of variations you can have in a product, should work...
Jun 30, 2022 (15 months ago)
Magnus
Photo of md5-7d2796ababc14477f4c09abc2e8edb05
Magnus
09:29 AM
Thank you Jason. I think I get the point, however, I am uncertain whether this can work with Instantsearch.js (React Instantsearch Hooks), as it seems to treat grouped document separately.

See pictures, for how it currently looks and the response result.

Instantsearch.js seems to have a distinct configure option but can that work with the typesense adapter — not sure if it’s at all relevant?

I’ve attempted to transform the hits but the hit results does not contain data about the group.

How would I go about combining them into a single ‘hit’ for Instantsearch?

Thank you 🙂
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:16 PM
> I’ve attempted to transform the hits but the hit results does not contain data about the group.
I was going to suggest this... but the adapter doesn't add this group information currently. Let me add this and give you a version to test
06:33
Jason
06:33 PM
Just published v2.4.2-0 of typesense-instantsearch-adapter, which will now add a group_key field to each hit. So you should be able to use that to group using transformHits
06:33
Jason
06:33 PM
Could you give it a shot and let me know how it goes?
Jul 01, 2022 (15 months ago)
Magnus
Photo of md5-7d2796ababc14477f4c09abc2e8edb05
Magnus
06:33 AM
I’ll give it shot and report back 🙂
10:29
Magnus
10:29 AM
Working great Jason 👍 Thank you.

I might have run into other troubles that I hadn’t thought about. But I’ll report back when I have more information 🙂

Anyhow, I might have to index variant information on every document. My current issue is, that I want to show shoe size availability and color variant on a single hit/model (product card). But with grouping I am not certain to get every document belonging to that group obviously. Eg. if I query “nike free blue”, I will only get the documents for the blue variant and not the red variant, even though I want to show that as well.

I haven’t explored the issue thoroughly yet. But if you have any ideas they’re more than welcome 😉
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:54 PM
Storing all variants information for a product on each variant document (as unindexed fields) might be the way to go