Skip to content

Commit a241b3e

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
fix: Add id field to sort config for consisteny pagination
The pagination does not work correctly for rel: `next` section in /search endpoint of the returned product list. This commit adds id parameter to sorting so that token obtains a unique value.
1 parent 5976d3c commit a241b3e

File tree

1 file changed

+5
-2
lines changed
  • stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database

1 file changed

+5
-2
lines changed

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ def populate_sort_shared(sortby: List) -> Optional[Dict[str, Dict[str, str]]]:
8080
This function transforms a list of sort specifications into the format required by
8181
Elasticsearch/OpenSearch for sorting query results. The returned dictionary can be
8282
directly used in search requests.
83+
Always includes 'id' as secondary sort to ensure unique pagination tokens.
8384
"""
8485
if sortby:
85-
return {s.field: {"order": s.direction} for s in sortby}
86+
sort_config = {s.field: {"order": s.direction} for s in sortby}
87+
sort_config.setdefault('id', {"order": "asc"})
88+
return sort_config
8689
else:
87-
return None
90+
return {"id": {"order": "asc"}}
8891

8992

9093
def add_collections_to_body(

0 commit comments

Comments
 (0)