Skip to content

Commit f32041d

Browse files
committed
cr
1 parent a539741 commit f32041d

File tree

17 files changed

+2058
-1289
lines changed

17 files changed

+2058
-1289
lines changed

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ async def post_search(
822822

823823
datetime_parsed = format_datetime_range(date_str=search_request.datetime)
824824
try:
825-
search, datetime_search = self.database.apply_datetime_filter(
825+
search = self.database.apply_datetime_filter(
826826
search=search, datetime=datetime_parsed
827827
)
828828
except (ValueError, TypeError) as e:
@@ -896,7 +896,7 @@ async def post_search(
896896
token=token_param,
897897
sort=sort,
898898
collection_ids=getattr(search_request, "collections", None),
899-
datetime_search=datetime_search,
899+
datetime_search=datetime_parsed,
900900
)
901901

902902
fields = getattr(search_request, "fields", None)

stac_fastapi/elasticsearch/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ dependencies = [
3333
"elasticsearch[async]~=8.19.1",
3434
"uvicorn~=0.23.0",
3535
"starlette>=0.35.0,<0.36.0",
36-
"redis==6.4.0",
3736
]
3837

3938
[project.urls]

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ def apply_collections_filter(search: Search, collection_ids: List[str]):
439439
return search.filter("terms", collection=collection_ids)
440440

441441
@staticmethod
442-
def apply_datetime_filter(
443-
search: Search, datetime: Optional[str]
444-
) -> Tuple[Search, Dict[str, Dict[str, Optional[str]]]]:
442+
def apply_datetime_filter(search: Search, datetime: Optional[str]) -> Search:
445443
"""Apply a filter to search on datetime, start_datetime, and end_datetime fields.
446444
447445
Args:
@@ -458,23 +456,8 @@ def apply_datetime_filter(
458456
# False: Always search only by start/end datetime
459457
USE_DATETIME = get_bool_env("USE_DATETIME", default=True)
460458

461-
result_metadata = {
462-
"datetime": {
463-
"gte": datetime_search.get("gte") if USE_DATETIME else None,
464-
"lte": datetime_search.get("lte") if USE_DATETIME else None,
465-
},
466-
"start_datetime": {
467-
"gte": datetime_search.get("gte") if not USE_DATETIME else None,
468-
"lte": None,
469-
},
470-
"end_datetime": {
471-
"gte": None,
472-
"lte": datetime_search.get("lte") if not USE_DATETIME else None,
473-
},
474-
}
475-
476459
if not datetime_search:
477-
return search, result_metadata
460+
return search
478461

479462
if USE_DATETIME:
480463
if "eq" in datetime_search:
@@ -551,10 +534,7 @@ def apply_datetime_filter(
551534
),
552535
]
553536

554-
return (
555-
search.query(Q("bool", should=should, minimum_should_match=1)),
556-
result_metadata,
557-
)
537+
return search.query(Q("bool", should=should, minimum_should_match=1))
558538
else:
559539
if "eq" in datetime_search:
560540
filter_query = Q(
@@ -588,7 +568,7 @@ def apply_datetime_filter(
588568
),
589569
],
590570
)
591-
return search.query(filter_query), result_metadata
571+
return search.query(filter_query)
592572

593573
@staticmethod
594574
def apply_bbox_filter(search: Search, bbox: List):
@@ -743,7 +723,7 @@ async def execute_search(
743723
token: Optional[str],
744724
sort: Optional[Dict[str, Dict[str, str]]],
745725
collection_ids: Optional[List[str]],
746-
datetime_search: Dict[str, Optional[str]],
726+
datetime_search: str,
747727
ignore_unavailable: bool = True,
748728
) -> Tuple[Iterable[Dict[str, Any]], Optional[int], Optional[str]]:
749729
"""Execute a search query with limit and other optional parameters.
@@ -754,7 +734,7 @@ async def execute_search(
754734
token (Optional[str]): The token used to return the next set of results.
755735
sort (Optional[Dict[str, Dict[str, str]]]): Specifies how the results should be sorted.
756736
collection_ids (Optional[List[str]]): The collection ids to search.
757-
datetime_search (Dict[str, Optional[str]]): Datetime range used for index selection.
737+
datetime_search (str): Datetime used for index selection.
758738
ignore_unavailable (bool, optional): Whether to ignore unavailable collections. Defaults to True.
759739
760740
Returns:
@@ -844,7 +824,7 @@ async def aggregate(
844824
geometry_geohash_grid_precision: int,
845825
geometry_geotile_grid_precision: int,
846826
datetime_frequency_interval: str,
847-
datetime_search,
827+
datetime_search: str,
848828
ignore_unavailable: Optional[bool] = True,
849829
):
850830
"""Return aggregations of STAC Items."""

stac_fastapi/opensearch/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ dependencies = [
3434
"opensearch-py[async]~=2.8.0",
3535
"uvicorn~=0.23.0",
3636
"starlette>=0.35.0,<0.36.0",
37-
"redis==6.4.0",
3837
]
3938

4039
[project.urls]

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,7 @@ def apply_free_text_filter(search: Search, free_text_queries: Optional[List[str]
457457
)
458458

459459
@staticmethod
460-
def apply_datetime_filter(
461-
search: Search, datetime: Optional[str]
462-
) -> Tuple[Search, Dict[str, Dict[str, Optional[str]]]]:
460+
def apply_datetime_filter(search: Search, datetime: Optional[str]) -> Search:
463461
"""Apply a filter to search on datetime, start_datetime, and end_datetime fields.
464462
465463
Args:
@@ -476,23 +474,8 @@ def apply_datetime_filter(
476474
# False: Always search only by start/end datetime
477475
USE_DATETIME = get_bool_env("USE_DATETIME", default=True)
478476

479-
result_metadata = {
480-
"datetime": {
481-
"gte": datetime_search.get("gte") if USE_DATETIME else None,
482-
"lte": datetime_search.get("lte") if USE_DATETIME else None,
483-
},
484-
"start_datetime": {
485-
"gte": datetime_search.get("gte") if not USE_DATETIME else None,
486-
"lte": None,
487-
},
488-
"end_datetime": {
489-
"gte": None,
490-
"lte": datetime_search.get("lte") if not USE_DATETIME else None,
491-
},
492-
}
493-
494477
if not datetime_search:
495-
return search, result_metadata
478+
return search
496479

497480
if USE_DATETIME:
498481
if "eq" in datetime_search:
@@ -569,10 +552,7 @@ def apply_datetime_filter(
569552
),
570553
]
571554

572-
return (
573-
search.query(Q("bool", should=should, minimum_should_match=1)),
574-
result_metadata,
575-
)
555+
return search.query(Q("bool", should=should, minimum_should_match=1))
576556
else:
577557
if "eq" in datetime_search:
578558
filter_query = Q(
@@ -606,7 +586,7 @@ def apply_datetime_filter(
606586
),
607587
],
608588
)
609-
return search.query(filter_query), result_metadata
589+
return search.query(filter_query)
610590

611591
@staticmethod
612592
def apply_bbox_filter(search: Search, bbox: List):
@@ -743,7 +723,7 @@ async def execute_search(
743723
token: Optional[str],
744724
sort: Optional[Dict[str, Dict[str, str]]],
745725
collection_ids: Optional[List[str]],
746-
datetime_search: Dict[str, Optional[str]],
726+
datetime_search: str,
747727
ignore_unavailable: bool = True,
748728
) -> Tuple[Iterable[Dict[str, Any]], Optional[int], Optional[str]]:
749729
"""Execute a search query with limit and other optional parameters.
@@ -754,7 +734,7 @@ async def execute_search(
754734
token (Optional[str]): The token used to return the next set of results.
755735
sort (Optional[Dict[str, Dict[str, str]]]): Specifies how the results should be sorted.
756736
collection_ids (Optional[List[str]]): The collection ids to search.
757-
datetime_search (Dict[str, Optional[str]]): Datetime range used for index selection.
737+
datetime_search (str): Datetime used for index selection.
758738
ignore_unavailable (bool, optional): Whether to ignore unavailable collections. Defaults to True.
759739
760740
Returns:
@@ -850,7 +830,7 @@ async def aggregate(
850830
geometry_geohash_grid_precision: int,
851831
geometry_geotile_grid_precision: int,
852832
datetime_frequency_interval: str,
853-
datetime_search,
833+
datetime_search: str,
854834
ignore_unavailable: Optional[bool] = True,
855835
):
856836
"""Return aggregations of STAC Items."""

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/aggregation/client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ async def aggregate(
313313
)
314314

315315
if aggregate_request.datetime:
316-
search, datetime_search = self.database.apply_datetime_filter(
316+
search = self.database.apply_datetime_filter(
317317
search=search, datetime=aggregate_request.datetime
318318
)
319-
else:
320-
datetime_search = {"gte": None, "lte": None}
321319

322320
if aggregate_request.bbox:
323321
bbox = aggregate_request.bbox
@@ -416,7 +414,7 @@ async def aggregate(
416414
geometry_geohash_grid_precision,
417415
geometry_geotile_grid_precision,
418416
datetime_frequency_interval,
419-
datetime_search,
417+
aggregate_request.datetime,
420418
)
421419
except Exception as error:
422420
if not isinstance(error, IndexError):

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/index.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def indices(collection_ids: Optional[List[str]]) -> str:
7171
def filter_indexes_by_datetime(
7272
collection_indexes: List[Tuple[Dict[str, str], ...]],
7373
datetime_search: Dict[str, Dict[str, Optional[str]]],
74+
use_datetime: bool,
7475
) -> List[str]:
7576
"""
7677
Filter Elasticsearch index aliases based on datetime search criteria.
@@ -85,6 +86,9 @@ def filter_indexes_by_datetime(
8586
datetime_search (Dict[str, Dict[str, Optional[str]]]): A dictionary with keys 'datetime',
8687
'start_datetime', and 'end_datetime', each containing 'gte' and 'lte' criteria as ISO format
8788
datetime strings or None.
89+
use_datetime (bool): Flag determining which datetime field to filter on:
90+
- True: Filters using 'datetime' alias.
91+
- False: Filters using 'start_datetime' and 'end_datetime' aliases.
8892
8993
Returns:
9094
List[str]: A list of start_datetime aliases that match all provided search criteria.
@@ -138,29 +142,30 @@ def check_criteria(
138142
end_datetime_alias = index_dict.get("end_datetime")
139143
datetime_alias = index_dict.get("datetime")
140144

141-
if not start_datetime_alias:
142-
continue
143-
144-
start_range = extract_date_from_alias(start_datetime_alias)
145-
end_date = extract_date_from_alias(end_datetime_alias)
146-
datetime_date = extract_date_from_alias(datetime_alias)
147-
148-
if not check_criteria(
149-
start_range[0], start_range[1], datetime_search.get("start_datetime", {})
150-
):
151-
continue
152-
if end_date:
145+
if start_datetime_alias:
146+
start_date = extract_date_from_alias(start_datetime_alias)
147+
if not check_criteria(
148+
start_date[0], start_date[1], datetime_search.get("start_datetime", {})
149+
):
150+
continue
151+
if end_datetime_alias:
152+
end_date = extract_date_from_alias(end_datetime_alias)
153153
if not check_criteria(
154154
end_date[0], end_date[1], datetime_search.get("end_datetime", {})
155155
):
156156
continue
157-
if datetime_date:
157+
if datetime_alias:
158+
datetime_date = extract_date_from_alias(datetime_alias)
158159
if not check_criteria(
159160
datetime_date[0], datetime_date[1], datetime_search.get("datetime", {})
160161
):
161162
continue
162163

163-
filtered_indexes.append(start_datetime_alias)
164+
primary_datetime_alias = (
165+
datetime_alias if use_datetime else start_datetime_alias
166+
)
167+
168+
filtered_indexes.append(primary_datetime_alias)
164169

165170
return filtered_indexes
166171

0 commit comments

Comments
 (0)