typesense / typesense/typesense

GroupBy Sorting Behavior with Multiple Sort Fields

Open
#2,133 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
26.6k
Forks
973
Avg merge
18h 45m
Merged PRs (30d)
4

Description

Description

When using group_by with multiple sort fields, where one field is _group_found, the secondary sort field appears to be ignored in the results.

Steps to Reproduce

The scenario involves products with multiple offers per product. The index "offers" is denormalized, with each offer containing the associated product data as additional fields.

When you:

  1. Group by product_id
  2. Sort by _group_found (to prioritize products with the most offers)
    The initial sorting works as expected.

Expected Behavior

Adding a second sort field price:asc with group_limit: 1 should return the lowest-priced offer for each product, while maintaining the primary sort by number of offers per product.

Actual Behavior

Using the sort configuration:

sort_by: '_group_found:desc, price:asc'

The results appear to only respect the _group_found sort order, while ignoring the secondary price sort field.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named. Start by reproducing the described grouped query against the denormalized "offers" index, using product_id, _group_found:desc, price:asc, and group_limit:1; done means the lowest-priced offer is selected for each product while _group_found remains the primary order.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.