diff --git a/CHANGELOG.md b/CHANGELOG.md index c99c10f4..3ffa151b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Collection-level Assets to the CollectionSerializer [#148](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/148) - -### Added - - Examples folder with example docker setup for running sfes from pip [#147](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/147) +- Added support for GET /search intersection queries [#158](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/158) ### Changed +- Updated core stac-fastapi libraries to 2.4.8 from 2.4.3 [#151](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/151) - Use aliases on Elasticsearch indices, add number suffix in index name. [#152](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/152) ### Fixed diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py index 776ac746..031a0235 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py @@ -4,7 +4,7 @@ from datetime import datetime as datetime_type from datetime import timezone from typing import Any, Dict, List, Optional, Set, Type, Union -from urllib.parse import urljoin +from urllib.parse import unquote_plus, urljoin import attr import stac_pydantic @@ -325,7 +325,7 @@ async def get_search( base_args["datetime"] = datetime if intersects: - base_args["intersects"] = intersects + base_args["intersects"] = json.loads(unquote_plus(intersects)) if sortby: # https://github.com/radiantearth/stac-spec/tree/master/api-spec/extensions/sort#http-get-or-post-form diff --git a/stac_fastapi/elasticsearch/tests/api/test_api.py b/stac_fastapi/elasticsearch/tests/api/test_api.py index c8edca78..3ae65ebd 100644 --- a/stac_fastapi/elasticsearch/tests/api/test_api.py +++ b/stac_fastapi/elasticsearch/tests/api/test_api.py @@ -2,6 +2,8 @@ import uuid from datetime import datetime, timedelta +import pytest + from ..conftest import create_collection, create_item ROUTES = { @@ -233,7 +235,29 @@ async def test_search_invalid_date(app_client, ctx): assert resp.status_code == 400 -async def test_search_point_intersects(app_client, ctx): +@pytest.mark.asyncio +async def test_search_point_intersects_get(app_client, ctx): + resp = await app_client.get( + '/search?intersects={"type":"Point","coordinates":[150.04,-33.14]}' + ) + + assert resp.status_code == 200 + resp_json = resp.json() + assert len(resp_json["features"]) == 1 + + +@pytest.mark.asyncio +async def test_search_polygon_intersects_get(app_client, ctx): + resp = await app_client.get( + '/search?intersects={"type":"Polygon","coordinates":[[[149.04, -34.14],[149.04, -32.14],[151.04, -32.14],[151.04, -34.14],[149.04, -34.14]]]}' + ) + + assert resp.status_code == 200 + resp_json = resp.json() + assert len(resp_json["features"]) == 1 + + +async def test_search_point_intersects_post(app_client, ctx): point = [150.04, -33.14] intersects = {"type": "Point", "coordinates": point}