Skip to content

Commit b3ed0d3

Browse files
YuriZmytrakovYuri Zmytrakov
andauthored
fix: Add id field to sort config for consisteny pagination (#421)
**Description:** 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. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [ ] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog --------- Co-authored-by: Yuri Zmytrakov <[email protected]>
1 parent d69f97f commit b3ed0d3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88

99
## [Unreleased]
1010

11+
- Added `id` field as secondary sort to sort config to ensure unique pagination tokens. [#421](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/421)
12+
- Added default environment variable `STAC_ITEM_LIMIT` to SFEOS for result limiting of returned items and STAC collections [#419](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/419)
13+
1114
### Changed
1215

1316
- Simplified Patch class and updated patch script creation including adding nest creation for merge patch [#420](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/420)
14-
- Added default environment variable `STAC_ITEM_LIMIT` to SFEOS for result limiting of returned items and STAC collections [#419](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/419)
1517

1618
## [v6.2.0] - 2025-08-27
1719

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)