Anyone have success implementing the grouping of results?
I’ve been trying some things with limited success. For example, I was able to use lodash to group the results and then render those in a custom v-for loop. But I ran into a problem where the grouping was only showing the grouped output of the first page of results. So it wasn’t an accurate result set. Ive also achieved success going the correlated multi-index search route - not sure if that’s the most efficient, but I can share more if anyone is interested.
Curious to see what you all might have ended up doing and if you’d be willing to share the details and code.
In the Algolia dashboard in the Indices->Configuration->Deduplication and Grouping area, I set the Distinct value to 4 (this can be any number depending on how many products you want to show per category), and the Attribute for Distinction to ’ cat_id ’ for my example.
This grouped all the categories with their products.
To make sure the Categories show first in the list, I added a Custom Ranking in the Indices->Configuration->Ranking and Sorting area in the Algolia dashboard.
I added a sort-by attribute of ’ type ’ and set it to ascending so that the ’ category ’ records would show before the ’ product ’ records in each group.
To set the ‘distinct’ parameter to more than 4 you can use this:
'distinct' => 7
Keep in mind that ‘distinct’ is a computationally expensive operation on large data sets, especially if distinct > 1.