Skip to content

add missing q param for item search and collection-items search #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
14 changes: 11 additions & 3 deletions stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[Union[List[str], str]] = None,
**kwargs,
) -> Collections:
"""Cross catalog search (GET).
Expand Down Expand Up @@ -359,6 +359,7 @@ async def item_collection(
filter_expr: Optional[str] = None,
filter_lang: Optional[str] = None,
token: Optional[str] = None,
q: Optional[Union[List[str], str]] = None,
**kwargs,
) -> ItemCollection:
"""Get all items from a specific collection.
Expand Down Expand Up @@ -391,6 +392,7 @@ async def item_collection(
filter_lang=filter_lang,
fields=fields,
sortby=sortby,
q=q,
)

try:
Expand Down Expand Up @@ -489,6 +491,7 @@ async def get_search(
filter_expr: Optional[str] = None,
filter_lang: Optional[str] = None,
token: Optional[str] = None,
q: Optional[Union[List[str], str]] = None,
**kwargs,
) -> ItemCollection:
"""Cross catalog search (GET).
Expand Down Expand Up @@ -516,6 +519,7 @@ async def get_search(
sortby=sortby,
filter_query=filter_expr,
filter_lang=filter_lang,
q=q,
)

try:
Expand Down Expand Up @@ -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[Union[List[str], str]] = None,
) -> Dict[str, Any]:
"""Clean up search arguments to match format expected by pgstac"""
if filter_query:
Expand Down Expand Up @@ -595,8 +599,12 @@ 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)
elif q:
base_args["q"] = q

# Remove None values from dict
clean = {}
Expand Down
Loading