@@ -394,7 +394,12 @@ async def get_document(self, document_id: str) -> dict[str, Any]:
394394 return response .json ()
395395
396396 async def get_documents (
397- self , * , offset : int = 0 , limit : int = 20 , fields : list [str ] | None = None
397+ self ,
398+ * ,
399+ offset : int = 0 ,
400+ limit : int = 20 ,
401+ fields : list [str ] | None = None ,
402+ filter : str | list [str | list [str ]] | None = None ,
398403 ) -> DocumentsInfo :
399404 """Get a batch documents from the index.
400405
@@ -404,6 +409,8 @@ async def get_documents(
404409 limit: Maximum number of documents returnedd. Defaults to 20.
405410 fields: Document attributes to show. If this value is None then all
406411 attributes are retrieved. Defaults to None.
412+ filter: Filter value information. Defaults to None. Note: This parameter can only be
413+ used with Meilisearch >= v1.2.0
407414
408415 Returns:
409416
@@ -427,11 +434,22 @@ async def get_documents(
427434 "limit" : limit ,
428435 }
429436
437+ if not filter :
438+ if fields :
439+ parameters ["fields" ] = "," .join (fields )
440+
441+ url = f"{ self ._documents_url } ?{ urlencode (parameters )} "
442+ response = await self ._http_requests .get (url )
443+
444+ return DocumentsInfo (** response .json ())
445+
430446 if fields :
431- parameters ["fields" ] = "," . join ( fields )
447+ parameters ["fields" ] = fields
432448
433- url = f"{ self ._documents_url } ?{ urlencode (parameters )} "
434- response = await self ._http_requests .get (url )
449+ parameters ["filter" ] = filter
450+
451+ url = f"{ self ._documents_url } /fetch"
452+ response = await self ._http_requests .post (url , body = parameters )
435453
436454 return DocumentsInfo (** response .json ())
437455
@@ -1307,6 +1325,67 @@ async def delete_documents(self, ids: list[str]) -> TaskInfo:
13071325
13081326 return TaskInfo (** response .json ())
13091327
1328+ async def delete_documents_by_filter (self , filter : str | list [str | list [str ]]) -> TaskInfo :
1329+ """Delete documents from the index by filter.
1330+
1331+ Args:
1332+
1333+ filter: The filter value information.
1334+
1335+ Returns:
1336+
1337+ The details of the task status.
1338+
1339+ Raises:
1340+
1341+ MeilisearchCommunicationError: If there was an error communicating with the server.
1342+ MeilisearchApiError: If the Meilisearch API returned an error.
1343+
1344+ Examples:
1345+
1346+ >>> from meilisearch_python_async import Client
1347+ >>> async with Client("http://localhost.com", "masterKey") as client:
1348+ >>> index = client.index("movies")
1349+ >>> await index.delete_documents_by_filter("genre=horor"))
1350+ """
1351+ url = f"{ self ._documents_url } /delete"
1352+ response = await self ._http_requests .post (url , body = {"filter" : filter })
1353+
1354+ return TaskInfo (** response .json ())
1355+
1356+ async def delete_documents_in_batches_by_filter (
1357+ self , filters : list [str | list [str | list [str ]]]
1358+ ) -> list [TaskInfo ]:
1359+ """Delete batches of documents from the index by filter.
1360+
1361+ Args:
1362+
1363+ filters: A list of filter value information.
1364+
1365+ Returns:
1366+
1367+ The a list of details of the task statuses.
1368+
1369+ Raises:
1370+
1371+ MeilisearchCommunicationError: If there was an error communicating with the server.
1372+ MeilisearchApiError: If the Meilisearch API returned an error.
1373+
1374+ Examples:
1375+
1376+ >>> from meilisearch_python_async import Client
1377+ >>> async with Client("http://localhost.com", "masterKey") as client:
1378+ >>> index = client.index("movies")
1379+ >>> await index.delete_documents_in_batches_by_filter(
1380+ >>> [
1381+ >>> "genre=horor"),
1382+ >>> "release_date=1520035200"),
1383+ >>> ]
1384+ >>> )
1385+ """
1386+ tasks = [self .delete_documents_by_filter (filter ) for filter in filters ]
1387+ return await gather (* tasks )
1388+
13101389 async def delete_all_documents (self ) -> TaskInfo :
13111390 """Delete all documents from the index.
13121391
0 commit comments