From 6e8d9dda8e5325a3bc27d3152ae18970a230636e Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Wed, 16 Jul 2025 19:12:39 -0400 Subject: [PATCH 1/3] add missing q param for item search and collection-items search (relates to #263) --- CHANGES.md | 3 +++ stac_fastapi/pgstac/core.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b838437b..045184d1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,9 @@ ### Changed +- add missing `q` parameters for free-text search extensions on `/search` + and `/collections/{collection_id}/items` endpoints +- add `str` type for `q` parameter when free-text advanced search extension is employed - rename `POSTGRES_HOST_READER` to `PGHOST` in config **breaking change** - rename `POSTGRES_USER` to `PGUSER` in config **breaking change** - rename `POSTGRES_PASS` to `PGPASSWORD` in config **breaking change** diff --git a/stac_fastapi/pgstac/core.py b/stac_fastapi/pgstac/core.py index 7854ad0d..af7ea334 100644 --- a/stac_fastapi/pgstac/core.py +++ b/stac_fastapi/pgstac/core.py @@ -54,7 +54,7 @@ async def all_collections( # noqa: C901 sortby: Optional[str] = None, filter_expr: Optional[str] = None, filter_lang: Optional[str] = None, - q: Optional[List[str]] = None, + q: Optional[List[str] | str] = None, **kwargs, ) -> Collections: """Cross catalog search (GET). @@ -359,6 +359,7 @@ async def item_collection( filter_expr: Optional[str] = None, filter_lang: Optional[str] = None, token: Optional[str] = None, + q: Optional[List[str] | str] = None, **kwargs, ) -> ItemCollection: """Get all items from a specific collection. @@ -391,6 +392,7 @@ async def item_collection( filter_lang=filter_lang, fields=fields, sortby=sortby, + q=q, ) try: @@ -489,6 +491,7 @@ async def get_search( filter_expr: Optional[str] = None, filter_lang: Optional[str] = None, token: Optional[str] = None, + q: Optional[List[str] | str] = None, **kwargs, ) -> ItemCollection: """Cross catalog search (GET). @@ -516,6 +519,7 @@ async def get_search( sortby=sortby, filter_query=filter_expr, filter_lang=filter_lang, + q=q, ) try: @@ -550,7 +554,7 @@ def _clean_search_args( # noqa: C901 sortby: Optional[str] = None, filter_query: Optional[str] = None, filter_lang: Optional[str] = None, - q: Optional[List[str]] = None, + q: Optional[List[str] | str] = None, ) -> Dict[str, Any]: """Clean up search arguments to match format expected by pgstac""" if filter_query: @@ -595,7 +599,9 @@ def _clean_search_args( # noqa: C901 base_args["fields"] = {"include": includes, "exclude": excludes} - if q: + # free-text search basic list[str] vs advanced str + # it is up to advanced to form the string properly + if isinstance(q, list): base_args["q"] = " OR ".join(q) # Remove None values from dict From 86f076208eef6741438974b984a5cba81e486313 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Wed, 16 Jul 2025 21:21:39 -0400 Subject: [PATCH 2/3] push q for advanced search --- stac_fastapi/pgstac/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stac_fastapi/pgstac/core.py b/stac_fastapi/pgstac/core.py index af7ea334..f4c13459 100644 --- a/stac_fastapi/pgstac/core.py +++ b/stac_fastapi/pgstac/core.py @@ -603,6 +603,8 @@ def _clean_search_args( # noqa: C901 # it is up to advanced to form the string properly if isinstance(q, list): base_args["q"] = " OR ".join(q) + elif q: + base_args["q"] = q # Remove None values from dict clean = {} From 60db97f4936fd821ec60288313faf477f0139f2f Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Wed, 16 Jul 2025 21:49:22 -0400 Subject: [PATCH 3/3] use old style union for consistency/bw-compat --- stac_fastapi/pgstac/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stac_fastapi/pgstac/core.py b/stac_fastapi/pgstac/core.py index f4c13459..3dbf25a1 100644 --- a/stac_fastapi/pgstac/core.py +++ b/stac_fastapi/pgstac/core.py @@ -54,7 +54,7 @@ async def all_collections( # noqa: C901 sortby: Optional[str] = None, filter_expr: Optional[str] = None, filter_lang: Optional[str] = None, - q: Optional[List[str] | str] = None, + q: Optional[Union[List[str], str]] = None, **kwargs, ) -> Collections: """Cross catalog search (GET). @@ -359,7 +359,7 @@ async def item_collection( filter_expr: Optional[str] = None, filter_lang: Optional[str] = None, token: Optional[str] = None, - q: Optional[List[str] | str] = None, + q: Optional[Union[List[str], str]] = None, **kwargs, ) -> ItemCollection: """Get all items from a specific collection. @@ -491,7 +491,7 @@ async def get_search( filter_expr: Optional[str] = None, filter_lang: Optional[str] = None, token: Optional[str] = None, - q: Optional[List[str] | str] = None, + q: Optional[Union[List[str], str]] = None, **kwargs, ) -> ItemCollection: """Cross catalog search (GET). @@ -554,7 +554,7 @@ def _clean_search_args( # noqa: C901 sortby: Optional[str] = None, filter_query: Optional[str] = None, filter_lang: Optional[str] = None, - q: Optional[List[str] | str] = None, + q: Optional[Union[List[str], str]] = None, ) -> Dict[str, Any]: """Clean up search arguments to match format expected by pgstac""" if filter_query: