#community-help

Sorting within Group_by with Group_limit

TLDR Morgan wants to sort within groups after grouping, Kishore Nallan offers advice and validates. Proposed solutions do not guarantee prioritizing inStock within groups.

Powered by Struct AI
Dec 21, 2021 (25 months ago)
Morgan
Photo of md5-9af47d330848eae988a5f9cc03e413f1
Morgan
03:58 PM
Hi, when using group_by and group_limit flag, is there any way to sort inside the group so we can use group_limit to just get the few entries we need?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:02 PM
👋 no way to custom sort within group by but group by items picked should already be sorted by query sort by order.
Morgan
Photo of md5-9af47d330848eae988a5f9cc03e413f1
Morgan
04:05 PM
thanks, I did not find any flag I can use to sort inside group. And the flag sort_by is used to sort the result. which can be tricky because the default search result sequence seems to be based on matching. exact match always comes first, but when using sort_by, that sequence is disrupted.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:07 PM
Got it. Can you give me an example of what type of sorting you are doing on the whole vs within the group by?
Morgan
Photo of md5-9af47d330848eae988a5f9cc03e413f1
Morgan
04:08 PM
the use case I have here is to sort the group as I need and take the first entry by using group_limit. I use the shoe example in the document, group_by=brand&group_limit=3 returns certain brands and limit 3, but what if I want to have a the first 3 to favor in_stock? something like group_by=brand&group_limit=3&group_sort_by:inStock:desc would help
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:10 PM
I have to confirm this behavior, but if you have a global sort_by=inStock:desc then even within the group the top-3 items based on inStock only will be picked I think. But maybe I am wrong.
Morgan
Photo of md5-9af47d330848eae988a5f9cc03e413f1
Morgan
04:12 PM
yeah, that was what I thought but seems not true. because when I added sort_by, it sorts the whole result with sort_by. and then the exact match which should be on the top of the result was trumped because it was less favorable regarding sort_by
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:13 PM
What if you did sort_by=_text_match:desc,inStock:desc
04:13
Kishore Nallan
04:13 PM
I will evaluate the grouping sorting in more detail later.
Morgan
Photo of md5-9af47d330848eae988a5f9cc03e413f1
Morgan
04:14 PM
sure, thanks so much Kishore, I will try that and post updates here.
updates: that seemed working for me. I will play and see.
_
_text_match works but looks like we still cannot get the inStock first in each group. After all, sort_by=_text_match:desc,inStock:desc works after 3 entries are taken from each group. The 3 entries taken are not guaranteed to have favored inStock.

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3011 threads (79% resolved)

Join Our Community

Similar Threads

Document Weighting and Sorting Discussion

SamHendley asked how to weight a document based on age and offered a sorting method. Jason clarified the method and suggested an RC for use. SamHendley tested and confirmed the solution. User Kishore Nallan assisted when an error occurred with a new feature.

1

30
11mo

Configuring InstantSearch.js Parameters and Comparing Search Results

John is having difficulty configuring InstantSearch.js parameters. Jason suggested how to utilize `facet_by` and `filter_by` widgets and advised checking network for search parameters. They also asked John to open an issue on the unexpected need for manual `_text_match` addition.

2

18
32mo

Tuning Query Results Order with Query_by_Weights

Nathan is trying to tune the order of results using `query_by_weights`, but experiences a smaller impact than expected. Jason suggests trying `max_weight` and sharing a snippet to further investigate.

1

8
6mo

Solving Conflicts in Searching and Ordering Data with Typesense

SamHendley faced an issue with search result order in Typesense. Kishore Nallan explained two behaviors that affected the ranking and pledged to change these, while also considering an additional suggestion from SamHendley. These changes were implemented in version `0.24.0.rcn39`.

18
12mo
Solved

Issues With `text_match` Scoring for Search Queries in Typesense

Colin encountered issues with the `text_match` scoring on Typesense v0.23.1. Jason and Kishore Nallan identified a potential issue with numeric overflow in the text match score and applied an unverified patch. The final resolution is unclear.

8

33
17mo