-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to delete documents by filter #756
Changes from 5 commits
c49b898
056ed0f
9e79e60
aaefae7
42d8218
24464e5
cc21b64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
from meilisearch._httprequests import HttpRequests | ||
from meilisearch.config import Config | ||
from meilisearch.errors import version_error_hint_message | ||
from meilisearch.models.document import Document, DocumentsResults | ||
from meilisearch.models.index import Faceting, IndexStats, Pagination, TypoTolerance | ||
from meilisearch.models.task import Task, TaskInfo, TaskResults | ||
|
@@ -729,12 +730,15 @@ def delete_document(self, document_id: Union[str, int]) -> TaskInfo: | |
) | ||
return TaskInfo(**response) | ||
|
||
def delete_documents(self, ids: List[Union[str, int]]) -> TaskInfo: | ||
def delete_documents( | ||
self, | ||
ids: List[Union[str, int]], | ||
) -> TaskInfo: | ||
"""Delete multiple documents from the index. | ||
|
||
Parameters | ||
---------- | ||
list: | ||
ids: | ||
List of unique identifiers of documents. | ||
|
||
Returns | ||
|
@@ -754,6 +758,34 @@ def delete_documents(self, ids: List[Union[str, int]]) -> TaskInfo: | |
) | ||
return TaskInfo(**response) | ||
|
||
@version_error_hint_message | ||
def delete_documents_by_filter( | ||
self, filter: Union[str, List[Union[str, List[str]]]] # pylint: disable=redefined-builtin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pylint doesn't like the parameter being named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me, it's ok to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pylint would be ok with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me, there is no problem to keep the same name as in the Meilisearch API. I will merge it |
||
) -> TaskInfo: | ||
"""Delete documents from the index by filter. | ||
|
||
Parameters | ||
---------- | ||
filter: | ||
The filter value information. | ||
|
||
Returns | ||
------- | ||
task_info: | ||
TaskInfo instance containing information about a task to track the progress of an asynchronous process. | ||
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task | ||
|
||
Raises | ||
------ | ||
MeilisearchApiError | ||
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors | ||
""" | ||
response = self.http.post( | ||
f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/delete", | ||
body={"filter": filter}, | ||
) | ||
return TaskInfo(**response) | ||
|
||
def delete_all_documents(self) -> TaskInfo: | ||
"""Delete all documents from the index. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, Dict, Iterator | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the new approach from the central issue, the idea should be to move the
delete_documents_by_filter
to the samedelete_documents
by adding a new argumentfilter
to the method. Also, I don't know how Python handles deprecations, but theids
argument should be deprecated in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brunoocasali I considered this new approach, but think it could be confusing. If a user sends both ids and a filter the filter will be silently ignored. Is this OK? Based on the message this means eventually you will only be able to delete by filter and not id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct!
I understand that could be strange at first sight, but the idea is to add the functionality and not break the current usage (without creating a new method just for a new use case).
Also, I understand that our SDKs (most of them) are not stable, but that is not the foresee I have for them. I believe breakings are always a bad sign, especially when they are not "expected" please remember the context explained here.
Since those SDKs are unstable, we can eliminate the mixed behavior when we move them to a v1 (not necessarily being directly related to the engine being on v2). Still, the cool thing is that we introduced warnings/deprecations to the users before doing it, so everyone is "ready".