-
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
Conversation
meilisearch/index.py
Outdated
@@ -754,6 +754,33 @@ def delete_documents(self, ids: List[Union[str, int]]) -> TaskInfo: | |||
) | |||
return TaskInfo(**response) | |||
|
|||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Pylint doesn't like the parameter being named filter
so I set it to ignore this error. If you would rather call it something else I can do that. If you want to rename do you have any suggestions for a name? I couldn't think of a good one.
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.
For me, it's ok to keep filter
. Is this the same issue with filters
in the plural?
I don't think we should give it any other name than the one it has
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.
pylint would be ok with filters
. The reason pylint doesn't like filter
is because python has a built in filter
function so it is trying to prevent overlap. In this case I can't think of a time where naming it filter
would actually cause any issues though so I think either ignoring the pylint error or renaming to filters
are both fine options, which ever you prefer.
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.
For me, there is no problem to keep the same name as in the Meilisearch API. I will merge it
Very nice ✨ If possible, can it be updated following this comment. |
@bidoubiwa continuing our discussion about the version helper here. If I run |
I also want to get your thoughts on combining |
And FYI, the tests are failing because 1.2.0-rc.1 was just released, but it hasn't finished publishing yet. I'll re-run once it's available. |
@sanders41 I've published new specs to be applied in this new version. Can you check it? (it is on the central issue) |
meilisearch/index.py
Outdated
def delete_documents(self, ids: List[Union[str, int]]) -> TaskInfo: | ||
def delete_documents( | ||
self, | ||
ids: List[Union[str, int]], |
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 same delete_documents
by adding a new argument filter
to the method. Also, I don't know how Python handles deprecations, but the ids
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".
@brunoocasali I updated as requested. I made filter a named only parameter so you can use |
I was in a hurry when writing my reason for using a named parameter for The first thing I wanted to prevent is with The second, and more important, is once |
Hey @sanders41 We discussed a bit to think about all possible options as we did not agree. Below you have the two design solutions we thought of. Which one do you think is best? Current behaviorThese behavior should NOT be breaking in any of the suggested designs delete_documents([1,2])
delete_documents(["1","2"])
delete_documents("1")
delete_documents(1)
delete_documents(ids=[1,2])
delete_documents(ids=["1","2"])
delete_documents(ids="1")
delete_documents(ids=1) Option 1: Named variablesdelete_documents(ids=[1,2], filter=["id = 1"]) # filter is ignored
delete_documents([1,2], filter=["id = 1"]) # filter is ignored
delete_documents(None, filter=["id = 1"]) # filter
delete_documents(filter=["id = 1"]) # filter
delete_documents(["id = 1"]) # fails as it is considered a document id Pros:
Cons:
Option 2: analyse first parameter typeIn this option we introduce
Based on the type of the first parameter Use old route if first param is:
Use new route if first param is:
delete_documents([1,2]) # document ids
delete_documents(ids=[1,2]) # document ids
delete_documents({ filter: ["id = 1"]}) # filter
delete_documents(ids={ filter: ["id = 1"]}) # filter Pros: Option 3: BothIt is possible to combine both option but implementation gets messy. |
I slightly lean towards option 1 even though I think it is ultimately a confusing option for the user. With this option I don't like the quasi optional parameters. The are listed as optional but really one or the other is required. With that said I think options 2's |
Hi @sanders41,
I kind of agree with you on this but I'm not really sure why. Did you find this solution more idiomatic to Python?
But it will be a breaking change at some point. |
I have a tendency to used named parameters (even when it isn't required) simply because it makes for less breaking changes. The parameters can be moved around, added to, etc without breaking my code. With this being my tendency, I would probably use Looking through code bases I probably see an equal amount of using named parameters and positional parameters. One isn't really more idiomatic over the other so unfortunately we can't really use that as the decision point. The one thing I can say here is Python has the option for specifying both position only arguments and named only arguments. |
Hey @sanders41 Since everyone seems to agree, let's go for solution 1 if that's okey for you |
I was about to say the same thing. Agreed |
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.
Thank you @sanders41 for the implementation of this release feature and the feedback on it 🚀
LGTM!
755: Changes related to the next Meilisearch release (v1.2.0) r=alallema a=meili-bot Related to this issue: meilisearch/integration-guides#261 This PR: - gathers the changes related to the next Meilisearch release (v1.2.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v1.2.0 is out.⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.2.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Done: - #756 - #757 Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com> Co-authored-by: Paul Sanders <psanders1@gmail.com> Co-authored-by: Amélie <alallema@users.noreply.github.com> Co-authored-by: alallema <amelie@meilisearch.com>
772: Update version for the next release (v0.28.0) r=alallema a=meili-bot Release CHANGELOG: This version introduces features released on Meilisearch v1.2.0 🎉 Check out the changelog of [Meilisearch v1.2.0](https://github.com/meilisearch/meilisearch/releases/tag/v1.2.0) for more information on the changes.⚠️ If you want to adopt new features of this release, **update the Meilisearch server** to the according version. ## 🚀 Enhancements * The method `delete_documents()` now supports a new parameter `filter` that allows deleting documents by filtering. The `filter` field works precisely like the `filter` field used on the `search` method. See [the docs on how to use filters](https://www.meilisearch.com/docs/learn/advanced/filtering#filter-basics). (#756) `@sanders41` * Add the ability to receive a `filter` key from the `get_documents`/`documents` methods. The `filter` field works precisely like the `filter` field used on the `search` method. See [the docs on how to use filters](https://www.meilisearch.com/docs/learn/advanced/filtering#filter-basics). (#757) `@sanders41` Thanks again to `@sanders41!` 🎉 Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com> Co-authored-by: Amélie <alallema@users.noreply.github.com>
Pull Request
Related issue
Fixes #<issue_number>
What does this PR do?
delete_documents_by_filter
methodPR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!