Skip to content

Commit 39c38fe

Browse files
committed
cr
1 parent eab070b commit 39c38fe

File tree

17 files changed

+2057
-1289
lines changed

17 files changed

+2057
-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
@@ -794,7 +794,7 @@ async def post_search(
794794

795795
datetime_parsed = format_datetime_range(date_str=search_request.datetime)
796796
try:
797-
search, datetime_search = self.database.apply_datetime_filter(
797+
search = self.database.apply_datetime_filter(
798798
search=search, datetime=datetime_parsed
799799
)
800800
except (ValueError, TypeError) as e:
@@ -868,7 +868,7 @@ async def post_search(
868868
token=token_param,
869869
sort=sort,
870870
collection_ids=getattr(search_request, "collections", None),
871-
datetime_search=datetime_search,
871+
datetime_search=datetime_parsed,
872872
)
873873

874874
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
@@ -434,9 +434,7 @@ def apply_collections_filter(search: Search, collection_ids: List[str]):
434434
return search.filter("terms", collection=collection_ids)
435435

436436
@staticmethod
437-
def apply_datetime_filter(
438-
search: Search, datetime: Optional[str]
439-
) -> Tuple[Search, Dict[str, Dict[str, Optional[str]]]]:
437+
def apply_datetime_filter(search: Search, datetime: Optional[str]) -> Search:
440438
"""Apply a filter to search on datetime, start_datetime, and end_datetime fields.
441439
442440
Args:
@@ -453,23 +451,8 @@ def apply_datetime_filter(
453451
# False: Always search only by start/end datetime
454452
USE_DATETIME = get_bool_env("USE_DATETIME", default=True)
455453

456-
result_metadata = {
457-
"datetime": {
458-
"gte": datetime_search.get("gte") if USE_DATETIME else None,
459-
"lte": datetime_search.get("lte") if USE_DATETIME else None,
460-
},
461-
"start_datetime": {
462-
"gte": datetime_search.get("gte") if not USE_DATETIME else None,
463-
"lte": None,
464-
},
465-
"end_datetime": {
466-
"gte": None,
467-
"lte": datetime_search.get("lte") if not USE_DATETIME else None,
468-
},
469-
}
470-
471454
if not datetime_search:
472-
return search, result_metadata
455+
return search
473456

474457
if USE_DATETIME:
475458
if "eq" in datetime_search:
@@ -546,10 +529,7 @@ def apply_datetime_filter(
546529
),
547530
]
548531

549-
return (
550-
search.query(Q("bool", should=should, minimum_should_match=1)),
551-
result_metadata,
552-
)
532+
return search.query(Q("bool", should=should, minimum_should_match=1))
553533
else:
554534
if "eq" in datetime_search:
555535
filter_query = Q(
@@ -583,7 +563,7 @@ def apply_datetime_filter(
583563
),
584564
],
585565
)
586-
return search.query(filter_query), result_metadata
566+
return search.query(filter_query)
587567

588568
@staticmethod
589569
def apply_bbox_filter(search: Search, bbox: List):
@@ -738,7 +718,7 @@ async def execute_search(
738718
token: Optional[str],
739719
sort: Optional[Dict[str, Dict[str, str]]],
740720
collection_ids: Optional[List[str]],
741-
datetime_search: Dict[str, Optional[str]],
721+
datetime_search: str,
742722
ignore_unavailable: bool = True,
743723
) -> Tuple[Iterable[Dict[str, Any]], Optional[int], Optional[str]]:
744724
"""Execute a search query with limit and other optional parameters.
@@ -749,7 +729,7 @@ async def execute_search(
749729
token (Optional[str]): The token used to return the next set of results.
750730
sort (Optional[Dict[str, Dict[str, str]]]): Specifies how the results should be sorted.
751731
collection_ids (Optional[List[str]]): The collection ids to search.
752-
datetime_search (Dict[str, Optional[str]]): Datetime range used for index selection.
732+
datetime_search (str): Datetime used for index selection.
753733
ignore_unavailable (bool, optional): Whether to ignore unavailable collections. Defaults to True.
754734
755735
Returns:
@@ -839,7 +819,7 @@ async def aggregate(
839819
geometry_geohash_grid_precision: int,
840820
geometry_geotile_grid_precision: int,
841821
datetime_frequency_interval: str,
842-
datetime_search,
822+
datetime_search: str,
843823
ignore_unavailable: Optional[bool] = True,
844824
):
845825
"""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)