Skip to content

Commit dfb4f32

Browse files
committed
Simplify functions
1 parent 58ed8b5 commit dfb4f32

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

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)