Skip to content

Commit

Permalink
Add check for content type if csv delimiter is used
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema committed Mar 21, 2023
1 parent a221f94 commit 24065cb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def add_documents_raw(
The type of document. Type available: 'csv', 'json', 'jsonl'.
csv_delimiter:
One ASCII character used to customize the delimiter for CSV.
Note: The csv delimiter can only be used with the Content-Type text/csv.
Returns
-------
Expand All @@ -518,8 +519,10 @@ def add_documents_raw(
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
"""

url = self._build_url(primary_key=primary_key, csv_delimiter=csv_delimiter)
if content_type == "text/csv":
url = self._build_url(primary_key=primary_key, csv_delimiter=csv_delimiter)
else:
url = self._build_url(primary_key=primary_key)
response = self.http.post(url, str_documents, content_type)
return TaskInfo(**response)

Expand Down Expand Up @@ -653,6 +656,7 @@ def update_documents_raw(
The type of document. Type available: 'csv', 'json', 'jsonl'
csv_delimiter:
One ASCII character used to customize the delimiter for CSV.
Note: The csv delimiter can only be used with the Content-Type text/csv.
Returns
-------
Expand All @@ -665,7 +669,10 @@ def update_documents_raw(
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
"""
url = self._build_url(primary_key=primary_key, csv_delimiter=csv_delimiter)
if content_type == "text/csv":
url = self._build_url(primary_key=primary_key, csv_delimiter=csv_delimiter)
else:
url = self._build_url(primary_key=primary_key)
response = self.http.put(url, str_documents, content_type)
return TaskInfo(**response)

Expand Down

0 comments on commit 24065cb

Please sign in to comment.