diff --git a/CHANGELOG.md b/CHANGELOG.md index 901e4d0d..870366c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed +- Aggregation bug fixes [#281](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/281) + ## [v3.0.0a3] - 2024-07-17 ### Added diff --git a/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py b/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py index ddab6829..facc8bcc 100644 --- a/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py +++ b/stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py @@ -271,7 +271,7 @@ def metric_agg(self, es_aggs, name, data_type): def get_filter(self, filter, filter_lang): """Format the filter parameter in cql2-json or cql2-text.""" if filter_lang == "cql2-text": - return orjson.loads(unquote_plus(to_cql2(parse_cql2_text(filter)))) + return orjson.loads(to_cql2(parse_cql2_text(filter))) elif filter_lang == "cql2-json": if isinstance(filter, str): return orjson.loads(unquote_plus(filter)) @@ -447,6 +447,8 @@ async def aggregate( status_code=400, detail=f"Aggregation {agg_name} not supported at catalog level", ) + + if aggregate_request.filter: try: search = self.database.apply_cql2_filter( search, aggregate_request.filter diff --git a/stac_fastapi/tests/extensions/test_aggregation.py b/stac_fastapi/tests/extensions/test_aggregation.py index 9ee4c708..dd471159 100644 --- a/stac_fastapi/tests/extensions/test_aggregation.py +++ b/stac_fastapi/tests/extensions/test_aggregation.py @@ -176,6 +176,19 @@ async def test_aggregate_filter_extension_eq_post(app_client, ctx): assert resp.json()["aggregations"][0]["value"] == 1 +@pytest.mark.asyncio +async def test_aggregate_filter_extension_neq_post(app_client, ctx): + params = { + "filter": {"op": "<>", "args": [{"property": "id"}, ctx.item["id"]]}, + "filter-lang": "cql2-json", + "aggregations": ["total_count"], + "collections": [ctx.item["collection"]], + } + resp = await app_client.post("/aggregate", json=params) + assert resp.status_code == 200 + assert resp.json()["aggregations"][0]["value"] == 0 + + @pytest.mark.asyncio async def test_aggregate_extension_gte_get(app_client, ctx): # there's one item that can match, so one of these queries should match it and the other shouldn't