#community-help

Request for Simplified Grouping Method with Typesense and Tanstack

TLDR Lalit has a problem with grouping data using Typesense and Tanstack due to nested JSON. They want an alternative method that simplifies the process. Jason has tried to understand the issue but hasn't offered a specific solution.

Powered by Struct AI
Aug 14, 2023 (1 month ago)
Lalit
Photo of md5-c1435479d3d68f5c9bf5faef1c3ba12f
Lalit
03:00 PM
i want to grup by typesense and i am using tanstack how
the issue is that i have to flatten the data and render is there any alternate available ?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:00 PM
Could you elaborate with an example?
Lalit
Photo of md5-c1435479d3d68f5c9bf5faef1c3ba12f
Lalit
03:03 PM
i want to group by using typesense and i am using tanstack which modified version of react-table

inside Group_key i am getting the groupped key but it is nested JSON i wanat to render the data from grouping typesense
03:03
Lalit
03:03 PM
to achieve that currently i am doing from the frontend i have destructured the data
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:07 PM
It’s still hard to understand the specifics, without an example. Could you share a sample search query, and the response you get from Typesense, and elaborate based on that?
Lalit
Photo of md5-c1435479d3d68f5c9bf5faef1c3ba12f
Lalit
03:59 PM
I am fetching the data from typesense, and grouping by a field. But in the hightlight > document, the data is nested. Is there any way to flatten the data when I use group by?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:01 PM
> the data is nested
I’m not sure I understand this part.

The structure of the highlight object in the response just follows your document’s original structure
Lalit
Photo of md5-c1435479d3d68f5c9bf5faef1c3ba12f
Lalit
04:17 PM
const variantItems = itemsArray.flatMap(({ variants, itemName, id }) =>
        variants?.flatMap(
          ({
            locations,
            name: variant,
            salesPrice,
            purchasePrice,
            discountedPrice,
            discountedPricePercentage,
          }) =>
            locations.flatMap(location => ({
              id,
              itemName,
              locationName: location.location.name,
              stock: location.currentQuantity,
              variant,
              salesPrice,
              purchasePrice,
              discountedPrice,
              discountedPricePercentage,
              status: 'In-stock',
            }))
        )
      )

this is how i am getting the values to group by from the frontend can i get it with less complexity