diff --git a/src/stac_fastapi/indexed/search/search_handler.py b/src/stac_fastapi/indexed/search/search_handler.py index 6fa50c0..932d6d6 100644 --- a/src/stac_fastapi/indexed/search/search_handler.py +++ b/src/stac_fastapi/indexed/search/search_handler.py @@ -17,7 +17,7 @@ from stac_index.indexer.stac_parser import StacParser from stac_pydantic.api.extensions.sort import SortDirections, SortExtension -from stac_fastapi.indexed.constants import rel_root, rel_self +from stac_fastapi.indexed.constants import collection_wildcard, rel_root, rel_self from stac_fastapi.indexed.db import fetchall, format_query_object_name, get_last_load_id from stac_fastapi.indexed.links.catalog import get_catalog_link from stac_fastapi.indexed.links.item import fix_item_links @@ -322,6 +322,7 @@ async def _include_filter(self) -> Optional[FilterClause]: search_request.filter, search_request.filter_lang ) queryable_config = await get_queryable_config_by_name() + collection_ids_for_queryables = self.search_request.collections or [] try: return ast_to_filter_clause( ast=ast, @@ -334,6 +335,9 @@ async def _include_filter(self) -> Optional[FilterClause]: is_temporal=entry.is_temporal, ) for entry in queryable_config.values() + if len(collection_ids_for_queryables) == 0 + or entry.collection_id == collection_wildcard + or entry.collection_id in collection_ids_for_queryables ], ) except UnknownField as e: diff --git a/tests/with_environment/integration_tests/test_get_search_filter.py b/tests/with_environment/integration_tests/test_get_search_filter.py index cfd731e..a7056fb 100644 --- a/tests/with_environment/integration_tests/test_get_search_filter.py +++ b/tests/with_environment/integration_tests/test_get_search_filter.py @@ -1,8 +1,10 @@ from datetime import datetime from typing import Any, Dict, List, cast +import requests from pytest import mark from shapely.geometry import Polygon +from with_environment.common import api_base_url from with_environment.integration_tests.common import ( all_get_search_results, compare_results_to_expected, @@ -315,3 +317,19 @@ def test_get_search_filter_temporal_range_intersect() -> None: } ), ) + + +def test_get_search_filter_non_queryable_property() -> None: + response = requests.get( + f"{api_base_url}/search", + params={ + "filter": { + "op": "=", + "args": [ + {"property": "non-existent-property"}, + "test-value", + ], + }, + }, + ) + assert response.status_code == 400 diff --git a/tests/with_environment/integration_tests/test_post_search_filter.py b/tests/with_environment/integration_tests/test_post_search_filter.py index 070dfe2..8d08dc5 100644 --- a/tests/with_environment/integration_tests/test_post_search_filter.py +++ b/tests/with_environment/integration_tests/test_post_search_filter.py @@ -1,7 +1,9 @@ from datetime import datetime from typing import Any, Dict, List, cast +import requests from shapely.geometry import Polygon, mapping +from with_environment.common import api_base_url from with_environment.integration_tests.common import ( all_post_search_results, compare_results_to_expected, @@ -429,3 +431,19 @@ def test_post_search_filter_temporal_range_intersect() -> None: } ), ) + + +def test_post_search_filter_non_queryable_property() -> None: + response = requests.post( + f"{api_base_url}/search", + json={ + "filter": { + "op": "=", + "args": [ + {"property": "non-existent-property"}, + "test-value", + ], + }, + }, + ) + assert response.status_code == 400