11from typing import Dict , Any , List , Optional , Union
22from meilisearch import Client
33
4+
45class DocumentManager :
56 """Manage documents within Meilisearch indexes"""
6-
7+
78 def __init__ (self , client : Client ):
89 self .client = client
910
@@ -12,23 +13,19 @@ async def get_documents(
1213 index_uid : str ,
1314 offset : Optional [int ] = None ,
1415 limit : Optional [int ] = None ,
15- fields : Optional [List [str ]] = None
16+ fields : Optional [List [str ]] = None ,
1617 ) -> Dict [str , Any ]:
1718 """Get documents from an index"""
1819 try :
1920 index = self .client .index (index_uid )
20- return index .get_documents ({
21- 'offset' : offset ,
22- 'limit' : limit ,
23- 'fields' : fields
24- })
21+ return index .get_documents (
22+ {"offset" : offset , "limit" : limit , "fields" : fields }
23+ )
2524 except Exception as e :
2625 raise Exception (f"Failed to get documents: { str (e )} " )
2726
2827 async def get_document (
29- self ,
30- index_uid : str ,
31- document_id : Union [str , int ]
28+ self , index_uid : str , document_id : Union [str , int ]
3229 ) -> Dict [str , Any ]:
3330 """Get a single document"""
3431 try :
@@ -41,7 +38,7 @@ async def add_documents(
4138 self ,
4239 index_uid : str ,
4340 documents : List [Dict [str , Any ]],
44- primary_key : Optional [str ] = None
41+ primary_key : Optional [str ] = None ,
4542 ) -> Dict [str , Any ]:
4643 """Add documents to an index"""
4744 try :
@@ -51,9 +48,7 @@ async def add_documents(
5148 raise Exception (f"Failed to add documents: { str (e )} " )
5249
5350 async def update_documents (
54- self ,
55- index_uid : str ,
56- documents : List [Dict [str , Any ]]
51+ self , index_uid : str , documents : List [Dict [str , Any ]]
5752 ) -> Dict [str , Any ]:
5853 """Update documents in an index"""
5954 try :
@@ -63,9 +58,7 @@ async def update_documents(
6358 raise Exception (f"Failed to update documents: { str (e )} " )
6459
6560 async def delete_document (
66- self ,
67- index_uid : str ,
68- document_id : Union [str , int ]
61+ self , index_uid : str , document_id : Union [str , int ]
6962 ) -> Dict [str , Any ]:
7063 """Delete a single document"""
7164 try :
@@ -75,9 +68,7 @@ async def delete_document(
7568 raise Exception (f"Failed to delete document: { str (e )} " )
7669
7770 async def delete_documents (
78- self ,
79- index_uid : str ,
80- document_ids : List [Union [str , int ]]
71+ self , index_uid : str , document_ids : List [Union [str , int ]]
8172 ) -> Dict [str , Any ]:
8273 """Delete multiple documents by ID"""
8374 try :
@@ -86,13 +77,10 @@ async def delete_documents(
8677 except Exception as e :
8778 raise Exception (f"Failed to delete documents: { str (e )} " )
8879
89- async def delete_all_documents (
90- self ,
91- index_uid : str
92- ) -> Dict [str , Any ]:
80+ async def delete_all_documents (self , index_uid : str ) -> Dict [str , Any ]:
9381 """Delete all documents in an index"""
9482 try :
9583 index = self .client .index (index_uid )
9684 return index .delete_all_documents ()
9785 except Exception as e :
98- raise Exception (f"Failed to delete all documents: { str (e )} " )
86+ raise Exception (f"Failed to delete all documents: { str (e )} " )
0 commit comments