@@ -695,7 +695,22 @@ async def create_collection(self, collection: Collection, refresh: bool = False)
695
695
await create_item_index (collection_id )
696
696
697
697
async def find_collection (self , collection_id : str ) -> Collection :
698
- """Database logic to find and return a collection."""
698
+ """Find and return a collection from the database.
699
+
700
+ Args:
701
+ self: The instance of the object calling this function.
702
+ collection_id (str): The ID of the collection to be found.
703
+
704
+ Returns:
705
+ Collection: The found collection, represented as a `Collection` object.
706
+
707
+ Raises:
708
+ NotFoundError: If the collection with the given `collection_id` is not found in the database.
709
+
710
+ Notes:
711
+ This function searches for a collection in the database using the specified `collection_id` and returns the found
712
+ collection as a `Collection` object. If the collection is not found, a `NotFoundError` is raised.
713
+ """
699
714
try :
700
715
collection = await self .client .get (
701
716
index = COLLECTIONS_INDEX , id = collection_id
@@ -706,7 +721,21 @@ async def find_collection(self, collection_id: str) -> Collection:
706
721
return collection ["_source" ]
707
722
708
723
async def delete_collection (self , collection_id : str , refresh : bool = False ):
709
- """Database logic for deleting one collection."""
724
+ """Delete a collection from the database.
725
+
726
+ Parameters:
727
+ self: The instance of the object calling this function.
728
+ collection_id (str): The ID of the collection to be deleted.
729
+ refresh (bool): Whether to refresh the index after the deletion (default: False).
730
+
731
+ Raises:
732
+ NotFoundError: If the collection with the given `collection_id` is not found in the database.
733
+
734
+ Notes:
735
+ This function first verifies that the collection with the specified `collection_id` exists in the database, and then
736
+ deletes the collection. If `refresh` is set to True, the index is refreshed after the deletion. Additionally, this
737
+ function also calls `delete_item_index` to delete the index for the items in the collection.
738
+ """
710
739
await self .find_collection (collection_id = collection_id )
711
740
await self .client .delete (
712
741
index = COLLECTIONS_INDEX , id = collection_id , refresh = refresh
@@ -716,7 +745,20 @@ async def delete_collection(self, collection_id: str, refresh: bool = False):
716
745
async def bulk_async (
717
746
self , collection_id : str , processed_items : List [Item ], refresh : bool = False
718
747
) -> None :
719
- """Database logic for async bulk item insertion."""
748
+ """Perform a bulk insert of items into the database asynchronously.
749
+
750
+ Args:
751
+ self: The instance of the object calling this function.
752
+ collection_id (str): The ID of the collection to which the items belong.
753
+ processed_items (List[Item]): A list of `Item` objects to be inserted into the database.
754
+ refresh (bool): Whether to refresh the index after the bulk insert (default: False).
755
+
756
+ Notes:
757
+ This function performs a bulk insert of `processed_items` into the database using the specified `collection_id`. The
758
+ insert is performed asynchronously, and the event loop is used to run the operation in a separate executor. The
759
+ `mk_actions` function is called to generate a list of actions for the bulk insert. If `refresh` is set to True, the
760
+ index is refreshed after the bulk insert. The function does not return any value.
761
+ """
720
762
await asyncio .get_event_loop ().run_in_executor (
721
763
None ,
722
764
lambda : helpers .bulk (
@@ -730,7 +772,20 @@ async def bulk_async(
730
772
def bulk_sync (
731
773
self , collection_id : str , processed_items : List [Item ], refresh : bool = False
732
774
) -> None :
733
- """Database logic for sync bulk item insertion."""
775
+ """Perform a bulk insert of items into the database synchronously.
776
+
777
+ Args:
778
+ self: The instance of the object calling this function.
779
+ collection_id (str): The ID of the collection to which the items belong.
780
+ processed_items (List[Item]): A list of `Item` objects to be inserted into the database.
781
+ refresh (bool): Whether to refresh the index after the bulk insert (default: False).
782
+
783
+ Notes:
784
+ This function performs a bulk insert of `processed_items` into the database using the specified `collection_id`. The
785
+ insert is performed synchronously and blocking, meaning that the function does not return until the insert has
786
+ completed. The `mk_actions` function is called to generate a list of actions for the bulk insert. If `refresh` is set to
787
+ True, the index is refreshed after the bulk insert. The function does not return any value.
788
+ """
734
789
helpers .bulk (
735
790
self .sync_client ,
736
791
mk_actions (collection_id , processed_items ),
0 commit comments