Skip to content

Commit 4e4b5eb

Browse files
committed
#179: filter extension - set filter-lang=cql2-text as default for GET search
1 parent 61c01cb commit 4e4b5eb

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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)