Skip to content

Commit 0cad96c

Browse files
authored
Merge pull request #180 from StijnCaerts/#179
Set correct default filter-lang for GET /search requests
2 parents ba11e0c + c38ce2b commit 0cad96c

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1919

2020
- Exclude unset fields in search response [#166](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166)
2121
- Upgrade stac-fastapi to v2.4.9 [#172](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/172)
22+
- Set correct default filter-lang for GET /search requests [#179](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/179)
2223

2324
## [v1.0.0]
2425

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,12 @@ async def get_search(
380380
base_args["sortby"] = sort_param
381381

382382
if filter:
383-
if filter_lang == "cql2-text":
383+
if filter_lang == "cql2-json":
384384
base_args["filter-lang"] = "cql2-json"
385-
base_args["filter"] = orjson.loads(to_cql2(parse_cql2_text(filter)))
385+
base_args["filter"] = orjson.loads(unquote_plus(filter))
386386
else:
387387
base_args["filter-lang"] = "cql2-json"
388-
base_args["filter"] = orjson.loads(unquote_plus(filter))
388+
base_args["filter"] = orjson.loads(to_cql2(parse_cql2_text(filter)))
389389

390390
if fields:
391391
includes = set()

stac_fastapi/elasticsearch/tests/extensions/test_filter.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ async def test_search_filter_ext_and_get(app_client, ctx):
101101
assert len(resp.json()["features"]) == 1
102102

103103

104+
@pytest.mark.asyncio
105+
async def test_search_filter_ext_and_get_id(app_client, ctx):
106+
collection = ctx.item["collection"]
107+
id = ctx.item["id"]
108+
filter = f"id='{id}' AND collection='{collection}'"
109+
resp = await app_client.get(f"/search?&filter={filter}")
110+
111+
assert resp.status_code == 200
112+
assert len(resp.json()["features"]) == 1
113+
114+
104115
@pytest.mark.asyncio
105116
async def test_search_filter_ext_and_get_cql2text_id(app_client, ctx):
106117
collection = ctx.item["collection"]
@@ -162,21 +173,21 @@ async def test_search_filter_ext_and_post(app_client, ctx):
162173
@pytest.mark.asyncio
163174
async def test_search_filter_extension_floats_get(app_client, ctx):
164175
resp = await app_client.get(
165-
"""/search?filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30891534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30691534"]}]}"""
176+
"""/search?filter-lang=cql2-json&filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30891534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30691534"]}]}"""
166177
)
167178

168179
assert resp.status_code == 200
169180
assert len(resp.json()["features"]) == 1
170181

171182
resp = await app_client.get(
172-
"""/search?filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item-7"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30891534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30691534"]}]}"""
183+
"""/search?filter-lang=cql2-json&filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item-7"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30891534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30691534"]}]}"""
173184
)
174185

175186
assert resp.status_code == 200
176187
assert len(resp.json()["features"]) == 0
177188

178189
resp = await app_client.get(
179-
"""/search?filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30591534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30491534"]}]}"""
190+
"""/search?filter-lang=cql2-json&filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30591534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30491534"]}]}"""
180191
)
181192

182193
assert resp.status_code == 200

0 commit comments

Comments
 (0)