@@ -342,7 +342,15 @@ def apply_collections_filter(search: Search, collection_ids: List[str]):
342
342
343
343
@staticmethod
344
344
def apply_datetime_filter (search : Search , datetime_search ):
345
- """Database logic to search datetime field."""
345
+ """Apply a filter to search based on datetime field.
346
+
347
+ Args:
348
+ search (Search): The search object to filter.
349
+ datetime_search (dict): The datetime filter criteria.
350
+
351
+ Returns:
352
+ Search: The filtered search object.
353
+ """
346
354
if "eq" in datetime_search :
347
355
search = search .filter (
348
356
"term" , ** {"properties__datetime" : datetime_search ["eq" ]}
@@ -392,7 +400,18 @@ def apply_intersects_filter(
392
400
search : Search ,
393
401
intersects : Geometry ,
394
402
):
395
- """Database logic to search a geojson object."""
403
+ """Filter search results based on intersecting geometry.
404
+
405
+ Args:
406
+ search (Search): The search object to apply the filter to.
407
+ intersects (Geometry): The intersecting geometry, represented as a GeoJSON-like object.
408
+
409
+ Returns:
410
+ search (Search): The search object with the intersecting geometry filter applied.
411
+
412
+ Notes:
413
+ A geo_shape filter is added to the search object, set to intersect with the specified geometry.
414
+ """
396
415
return search .filter (
397
416
Q (
398
417
{
@@ -411,7 +430,18 @@ def apply_intersects_filter(
411
430
412
431
@staticmethod
413
432
def apply_stacql_filter (search : Search , op : str , field : str , value : float ):
414
- """Database logic to perform query for search endpoint."""
433
+ """Filter search results based on a comparison between a field and a value.
434
+
435
+ Args:
436
+ search (Search): The search object to apply the filter to.
437
+ op (str): The comparison operator to use. Can be 'eq' (equal), 'gt' (greater than), 'gte' (greater than or equal),
438
+ 'lt' (less than), or 'lte' (less than or equal).
439
+ field (str): The field to perform the comparison on.
440
+ value (float): The value to compare the field against.
441
+
442
+ Returns:
443
+ search (Search): The search object with the specified filter applied.
444
+ """
415
445
if op != "eq" :
416
446
key_filter = {field : {f"{ op } " : value }}
417
447
search = search .filter (Q ("range" , ** key_filter ))
@@ -444,7 +474,27 @@ async def execute_search(
444
474
collection_ids : Optional [List [str ]],
445
475
ignore_unavailable : bool = True ,
446
476
) -> Tuple [Iterable [Dict [str , Any ]], Optional [int ], Optional [str ]]:
447
- """Database logic to execute search with limit."""
477
+ """Execute a search query with limit and other optional parameters.
478
+
479
+ Args:
480
+ search (Search): The search query to be executed.
481
+ limit (int): The maximum number of results to be returned.
482
+ token (Optional[str]): The token used to return the next set of results.
483
+ sort (Optional[Dict[str, Dict[str, str]]]): Specifies how the results should be sorted.
484
+ collection_ids (Optional[List[str]]): The collection ids to search.
485
+ ignore_unavailable (bool, optional): Whether to ignore unavailable collections. Defaults to True.
486
+
487
+ Returns:
488
+ Tuple[Iterable[Dict[str, Any]], Optional[int], Optional[str]]: A tuple containing:
489
+ - An iterable of search results, where each result is a dictionary with keys and values representing the
490
+ fields and values of each document.
491
+ - The total number of results (if the count could be computed), or None if the count could not be
492
+ computed.
493
+ - The token to be used to retrieve the next set of results, or None if there are no more results.
494
+
495
+ Raises:
496
+ NotFoundError: If the collections specified in `collection_ids` do not exist.
497
+ """
448
498
search_after = None
449
499
if token :
450
500
search_after = urlsafe_b64decode (token .encode ()).decode ().split ("," )
@@ -536,7 +586,18 @@ def sync_prep_create_item(self, item: Item, base_url: str) -> Item:
536
586
return self .item_serializer .stac_to_db (item , base_url )
537
587
538
588
async def create_item (self , item : Item , refresh : bool = False ):
539
- """Database logic for creating one item."""
589
+ """Database logic for creating one item.
590
+
591
+ Args:
592
+ item (Item): The item to be created.
593
+ refresh (bool, optional): Refresh the index after performing the operation. Defaults to False.
594
+
595
+ Raises:
596
+ ConflictError: If the item already exists in the database.
597
+
598
+ Returns:
599
+ None
600
+ """
540
601
# todo: check if collection exists, but cache
541
602
item_id = item ["id" ]
542
603
collection_id = item ["collection" ]
@@ -555,7 +616,16 @@ async def create_item(self, item: Item, refresh: bool = False):
555
616
async def delete_item (
556
617
self , item_id : str , collection_id : str , refresh : bool = False
557
618
):
558
- """Database logic for deleting one item."""
619
+ """Delete a single item from the database.
620
+
621
+ Args:
622
+ item_id (str): The id of the Item to be deleted.
623
+ collection_id (str): The id of the Collection that the Item belongs to.
624
+ refresh (bool, optional): Whether to refresh the index after the deletion. Default is False.
625
+
626
+ Raises:
627
+ NotFoundError: If the Item does not exist in the database.
628
+ """
559
629
try :
560
630
await self .client .delete (
561
631
index = index_by_collection_id (collection_id ),
0 commit comments