Skip to content

Commit ace2899

Browse files
gtesoroGuillermo Tesoro Calvo
andauthored
fix: Fixed free-text search (#48)
Even though `stac-fastapi-eodag` defined the `q` parameter as an optional string in `all_collections`, this seems to be ignored by fastapi since the `q` is defined by the module `stac-fastapi` on the free_text extension as a list of strings. This requires the `q` parameter to be expanded, using AND by default, which can be parsed by the eodag free-text parser. --------- Co-authored-by: Guillermo Tesoro Calvo <guillermo.tesoro@c-ssystems.de>
1 parent a9d2192 commit ace2899

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

stac_fastapi/eodag/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class EodagCoreClient(CustomCoreClient):
9595

9696
def _get_collection(self, product_type: dict[str, Any], request: Request) -> Collection:
9797
"""Convert a EODAG produt type to a STAC collection."""
98+
9899
collection = Collection(deepcopy(request.app.state.ext_stac_collections.get(product_type["ID"], {})))
99100

100101
platform_value = [p for p in (product_type.get("platformSerialIdentifier") or "").split(",") if p]
@@ -224,7 +225,7 @@ async def all_collections(
224225
datetime: Optional[str] = None,
225226
limit: Optional[int] = 10,
226227
offset: Optional[int] = 0,
227-
q: Optional[str] = None,
228+
q: Optional[list[str]] = None,
228229
query: Optional[str] = None,
229230
) -> Collections:
230231
"""
@@ -260,9 +261,13 @@ async def all_collections(
260261
if any((q, datetime)):
261262
start, end = dt_range_to_eodag(str_to_interval(datetime))
262263

264+
# q is always a list, per stac-api free_text extension definiton
265+
# Expanding with AND as default.
266+
free_text = " AND ".join(q or [])
267+
263268
try:
264269
guessed_product_types = request.app.state.dag.guess_product_type(
265-
free_text=q, missionStartDate=start, missionEndDate=end
270+
free_text=free_text, missionStartDate=start, missionEndDate=end
266271
)
267272
except EodagNoMatchingProductType:
268273
product_types = []

tests/test_collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def test_search_collections_freetext_ok(app_client, mock_list_product_type
7676
r = await app_client.get("/collections?q=TERM1,TERM2")
7777
assert mock_list_product_types.called
7878
mock_guess_product_type.assert_called_once_with(
79-
free_text=["TERM1", "TERM2"], missionStartDate=None, missionEndDate=None
79+
free_text="TERM1 AND TERM2", missionStartDate=None, missionEndDate=None
8080
)
8181
assert r.status_code == 200
8282
assert ["S2_MSI_L1C"] == [col["id"] for col in r.json().get("collections", [])]
@@ -146,7 +146,7 @@ async def test_search_collections_datetime(app_client, mock_list_product_types,
146146
r = await app_client.get(f"/collections?datetime={start}/{end}")
147147

148148
assert mock_list_product_types.called
149-
mock_guess_product_type.assert_called_once_with(free_text=None, missionStartDate=start, missionEndDate=end)
149+
mock_guess_product_type.assert_called_once_with(free_text="", missionStartDate=start, missionEndDate=end)
150150
assert r.status_code == 200
151151
assert ["S2_MSI_L1C"] == [col["id"] for col in r.json().get("collections", [])]
152152

0 commit comments

Comments
 (0)