8000 Support boolean parameters in `Index.get_documents` by martinnj · Pull Request #1045 · meilisearch/meilisearch-python · GitHub
[go: up one dir, main page]

Skip to content

Support boolean parameters in Index.get_documents #1045

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
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ index.search(

## 🤖 Compatibility with Meilisearch

This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-python/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.
This package guarantees compatibility with [version v1.2 and above of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-python/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.

## 💡 Learn more

Expand Down
7 changes: 6 additions & 1 deletion meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ def send_request(
data=body,
)
else:
data = json.dumps(body, cls=serializer) if body else "" if body == "" else "null"
serialize_body = isinstance(body, dict) or body
data = (
json.dumps(body, cls=serializer)
if serialize_body
else "" if body == "" else "null"
)

request = http_method(
request_path, timeout=self.config.timeout, headers=self.headers, data=data
Expand Down
13 changes: 2 additions & 11 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,8 @@ def get_documents(
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
if parameters is None or parameters.get("filter") is None:
if parameters is None:
parameters = {}
elif "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)}"
)
return DocumentsResults(response)

if parameters is None:
parameters = {}
response = self.http.post(
f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/fetch",
body=parameters,
Expand Down
2 changes: 1 addition & 1 deletion tests/index/test_index_document_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_get_documents_offset_optional_params(index_with_documents):
response = index.get_documents()
assert isinstance(response.results, list)
assert len(response.results) == 20
response_offset_limit = index.get_documents({"limit": 3, "offset": 1, "fields": "title"})
response_offset_limit = index.get_documents({"limit": 3, "offset": 1, "fields": ["title"]})
assert len(response_offset_limit.results) == 3
assert hasattr(response_offset_limit.results[0], "title")
assert response_offset_limit.results[0].title == response.results[1].title
Expand Down
Loading
0