Skip to content

Commit e5393c3

Browse files
committed
add free-text search extension
1 parent ee19252 commit e5393c3

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

stac_fastapi/pgstac/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from stac_fastapi.extensions.core import (
2020
FieldsExtension,
2121
FilterExtension,
22+
FreeTextExtension,
2223
SortExtension,
2324
TokenPaginationExtension,
2425
TransactionExtension,
@@ -46,6 +47,7 @@
4647
"fields": FieldsExtension(),
4748
"pagination": TokenPaginationExtension(),
4849
"filter": FilterExtension(client=FiltersClient()),
50+
"free_text": FreeTextExtension(),
4951
"bulk_transactions": BulkTransactionExtension(client=BulkTransactionsClient()),
5052
}
5153

@@ -55,6 +57,7 @@
5557
"sort": SortExtension(),
5658
"fields": FieldsExtension(),
5759
"filter": FilterExtension(client=FiltersClient()),
60+
"free_text": FreeTextExtension(),
5861
}
5962

6063
enabled_extensions = (

stac_fastapi/pgstac/core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async def all_collections( # noqa: C901
5252
sortby: Optional[str] = None,
5353
filter: Optional[str] = None,
5454
filter_lang: Optional[str] = None,
55+
q: Optional[List[str]] = None,
5556
**kwargs,
5657
) -> Collections:
5758
"""Cross catalog search (GET).
@@ -79,6 +80,7 @@ async def all_collections( # noqa: C901
7980
sortby=sortby,
8081
filter_query=filter,
8182
filter_lang=filter_lang,
83+
q=q,
8284
)
8385

8486
async with request.app.state.get_connection(request, "r") as conn:
@@ -451,6 +453,7 @@ async def get_search(
451453
sortby: Optional[str] = None,
452454
filter: Optional[str] = None,
453455
filter_lang: Optional[str] = None,
456+
q: Optional[List[str]] = None,
454457
**kwargs,
455458
) -> ItemCollection:
456459
"""Cross catalog search (GET).
@@ -478,6 +481,7 @@ async def get_search(
478481
sortby=sortby,
479482
filter_query=filter,
480483
filter_lang=filter_lang,
484+
q=q,
481485
)
482486

483487
# Do the request
@@ -499,6 +503,7 @@ def clean_search_args( # noqa: C901
499503
sortby: Optional[str] = None,
500504
filter_query: Optional[str] = None,
501505
filter_lang: Optional[str] = None,
506+
q: Optional[List[str]] = None,
502507
) -> Dict[str, Any]:
503508
"""Clean up search arguments to match format expected by pgstac"""
504509
if filter_query:
@@ -541,6 +546,9 @@ def clean_search_args( # noqa: C901
541546
includes.add(field)
542547
base_args["fields"] = {"include": includes, "exclude": excludes}
543548

549+
if q:
550+
base_args["q"] = " OR ".join(q)
551+
544552
# Remove None values from dict
545553
clean = {}
546554
for k, v in base_args.items():

tests/resources/test_collection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,11 @@ async def test_get_collections_search(
303303
"/collections",
304304
)
305305
assert len(resp.json()["collections"]) == 2
306+
307+
# free-text
308+
resp = await app_client.get(
309+
"/collections",
310+
params={"q": "temperature"},
311+
)
312+
assert len(resp.json()["collections"]) == 1
313+
assert resp.json()["collections"][0]["id"] == load_test2_collection.id

0 commit comments

Comments
 (0)