Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add ability to get documents with a filter #757

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

Merged
merged 3 commits into from
May 23, 2023

Conversation

sanders41
Copy link
Collaborator

Pull Request

Note: There is still some discussion about the best way to handle this so it may need some updates.

Related issue

Fixes #<issue_number>

What does this PR do?

  • Adds filter to the parameters for get_documents

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@sanders41 sanders41 added the enhancement New feature or request label May 17, 2023
@@ -308,6 +308,7 @@ def get_documents(self, parameters: Optional[Dict[str, Any]] = None) -> Document
----------
parameters (optional):
parameters accepted by the get documents route: https://docs.meilisearch.com/reference/api/documents.html#get-documents
Note: The filter parameter is only available in Meilisearch >= 1.2.0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Comment on lines 329 to 340
response = self.http.get(
f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{parse.urlencode(parameters)}"
)
return DocumentsResults(response)

if not parameters.get("filter"):
if "fields" in parameters and isinstance(parameters["fields"], list):
parameters["fields"] = ",".join(parameters["fields"])

response = self.http.get(
f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{parse.urlencode(parameters)}"
response = self.http.get(
f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{parse.urlencode(parameters)}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can find a way to avoid having to write two times the get request

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't happy with that either. I refactored it. It's still slightly more verbose than I would like, but because of the way it is using the dictionary for parameters I had a hard time coming up with something better.

Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect 🤩 Thanks you @sanders41
LGTM!

@alallema alallema merged commit 760ee7d into bump-meilisearch-v1.2.0 May 23, 2023
@alallema alallema deleted the get-documents-by-filter branch May 23, 2023 12:16
meili-bors bot added a commit that referenced this pull request Jun 5, 2023
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 <[email protected]>
Co-authored-by: Paul Sanders <[email protected]>
Co-authored-by: Amélie <[email protected]>
Co-authored-by: alallema <[email protected]>
meili-bors bot added a commit that referenced this pull request Jun 5, 2023
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 <[email protected]>
Co-authored-by: Amélie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants