Skip to content

Commit 1da6c8b

Browse files
committed
Simplify functions
1 parent 58ed8b5 commit 1da6c8b

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

meilisearch/_httprequests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def send_request(
1919
self,
2020
http_method: Callable,
2121
path: str,
22-
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
22+
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str], str]] = None,
2323
content_type: Optional[str] = None,
2424
) -> Any:
2525
if content_type:
@@ -55,7 +55,7 @@ def get(
5555
def post(
5656
self,
5757
path: str,
58-
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
58+
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str], str]] = None,
5959
content_type: Optional[str] = 'application/json',
6060
) -> Any:
6161
return self.send_request(requests.post, path, body, content_type)

meilisearch/index.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def add_documents_json(
411411
MeiliSearchApiError
412412
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
413413
"""
414-
return self.add_documents_raw(str_documents, primary_key, 'json')
414+
return self.add_documents_raw(str_documents, primary_key, 'application/json')
415415

416416
def add_documents_csv(
417417
self,
@@ -438,7 +438,7 @@ def add_documents_csv(
438438
MeiliSearchApiError
439439
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
440440
"""
441-
return self.add_documents_raw(str_documents, primary_key, 'csv')
441+
return self.add_documents_raw(str_documents, primary_key, 'text/csv')
442442

443443
def add_documents_ndjson(
444444
self,
@@ -465,13 +465,13 @@ def add_documents_ndjson(
465465
MeiliSearchApiError
466466
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
467467
"""
468-
return self.add_documents_raw(str_documents, primary_key, 'jsonl')
468+
return self.add_documents_raw(str_documents, primary_key, 'application/x-ndjson')
469469

470470
def add_documents_raw(
471471
self,
472472
str_documents: str,
473473
primary_key: Optional[str] = None,
474-
doc_type: Optional[str] = None,
474+
content_type: Optional[str] = None,
475475
) -> Dict[str, int]:
476476
"""Add string documents to the index.
477477
@@ -496,12 +496,6 @@ def add_documents_raw(
496496
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
497497
"""
498498
url = self._build_url(primary_key)
499-
if doc_type == "json":
500-
content_type = 'application/json'
501-
if doc_type == "jsonl":
502-
content_type = 'application/x-ndjson'
503-
if doc_type == "csv":
504-
content_type = 'text/csv'
505499
return self.http.post(url, str_documents, content_type)
506500

507501
def update_documents(
@@ -1250,6 +1244,5 @@ def _build_url(
12501244
):
12511245
if primary_key is None:
12521246
return f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}'
1253-
else:
1254-
primary_key = urllib.parse.urlencode({'primaryKey': primary_key})
1255-
return f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{primary_key}'
1247+
primary_key = urllib.parse.urlencode({'primaryKey': primary_key})
1248+
return f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{primary_key}'

0 commit comments

Comments
 (0)