Skip to content

Commit ca64ba3

Browse files
committed
Filter fix.
1 parent 3d5b168 commit ca64ba3

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ async def get_search(
459459
sortby: Optional[str] = None,
460460
q: Optional[List[str]] = None,
461461
intersects: Optional[str] = None,
462-
filter: Optional[str] = None,
462+
filter_expr: Optional[str] = None,
463463
filter_lang: Optional[str] = None,
464464
**kwargs,
465465
) -> stac_types.ItemCollection:
@@ -507,12 +507,13 @@ async def get_search(
507507
for sort in sortby
508508
]
509509

510-
if filter:
510+
if filter_expr:
511+
print("GET FE", filter_expr)
511512
base_args["filter-lang"] = "cql2-json"
512513
base_args["filter"] = orjson.loads(
513-
unquote_plus(filter)
514+
unquote_plus(filter_expr)
514515
if filter_lang == "cql2-json"
515-
else to_cql2(parse_cql2_text(filter))
516+
else to_cql2(parse_cql2_text(filter_expr))
516517
)
517518

518519
if fields:
@@ -594,10 +595,11 @@ async def post_search(
594595
)
595596

596597
# only cql2_json is supported here
597-
if hasattr(search_request, "filter"):
598-
cql2_filter = getattr(search_request, "filter", None)
598+
if search_request.filter_expr:
599599
try:
600-
search = self.database.apply_cql2_filter(search, cql2_filter)
600+
search = self.database.apply_cql2_filter(
601+
search, search_request.filter_expr
602+
)
601603
except Exception as e:
602604
raise HTTPException(
603605
status_code=400, detail=f"Error with cql2_json filter: {e}"

stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ async def aggregate(
338338
datetime: Optional[DateTimeType] = None,
339339
intersects: Optional[str] = None,
340340
filter_lang: Optional[str] = None,
341-
filter: Optional[str] = None,
341+
filter_expr: Optional[str] = None,
342342
aggregations: Optional[str] = None,
343343
ids: Optional[List[str]] = None,
344344
bbox: Optional[BBox] = None,
@@ -380,8 +380,8 @@ async def aggregate(
380380
if datetime:
381381
base_args["datetime"] = self._format_datetime_range(datetime)
382382

383-
if filter:
384-
base_args["filter"] = self.get_filter(filter, filter_lang)
383+
if filter_expr:
384+
base_args["filter"] = self.get_filter(filter_expr, filter_lang)
385385
aggregate_request = EsAggregationExtensionPostRequest(**base_args)
386386
else:
387387
# Workaround for optional path param in POST requests

stac_fastapi/core/stac_fastapi/core/utilities.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
from typing import Any, Dict, List, Optional, Set, Union
99

1010
from stac_fastapi.core.models.patch import ElasticPath
11-
from stac_fastapi.types.stac import (
12-
Item,
13-
PatchAddReplaceTest,
14-
PatchOperation,
15-
PatchRemove,
16-
)
11+
from stac_fastapi.types.stac import Item, PatchOperation
1712

1813
MAX_LIMIT = 10000
1914

@@ -157,7 +152,7 @@ def merge_to_operations(data: Dict) -> List:
157152
for key, value in data.copy().items():
158153

159154
if value is None:
160-
operations.append(PatchRemove(op="remove", path=key))
155+
operations.append(PatchOperation(op="remove", path=key))
161156

162157
elif isinstance(value, dict):
163158
nested_operations = merge_to_operations(value)
@@ -167,7 +162,7 @@ def merge_to_operations(data: Dict) -> List:
167162
operations.append(nested_operation)
168163

169164
else:
170-
operations.append(PatchAddReplaceTest(op="add", path=key, value=value))
165+
operations.append(PatchOperation(op="add", path=key, value=value))
171166

172167
return operations
173168

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ def apply_free_text_filter(search: Search, free_text_queries: Optional[List[str]
619619
return search
620620

621621
@staticmethod
622-
def apply_cql2_filter(search: Search, _filter: Optional[Dict[str, Any]]):
622+
def apply_cql2_filter(search: Search, filter_expr: Optional[Dict[str, Any]]):
623623
"""
624624
Apply a CQL2 filter to an Elasticsearch Search object.
625625
@@ -638,8 +638,8 @@ def apply_cql2_filter(search: Search, _filter: Optional[Dict[str, Any]]):
638638
Search: The modified Search object with the filter applied if a filter is provided,
639639
otherwise the original Search object.
640640
"""
641-
if _filter is not None:
642-
es_query = filter.to_es(_filter)
641+
if filter_expr is not None:
642+
es_query = filter.to_es(filter_expr)
643643
search = search.query(es_query)
644644

645645
return search

0 commit comments

Comments
 (0)