Skip to content

Commit

Permalink
Simplify functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema committed Oct 6, 2021
1 parent 58ed8b5 commit dfb4f32
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def add_documents_json(
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
"""
return self.add_documents_raw(str_documents, primary_key, 'json')
return self.add_documents_raw(str_documents, primary_key, 'application/json')

def add_documents_csv(
self,
Expand All @@ -438,7 +438,7 @@ def add_documents_csv(
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
"""
return self.add_documents_raw(str_documents, primary_key, 'csv')
return self.add_documents_raw(str_documents, primary_key, 'text/csv')

def add_documents_ndjson(
self,
Expand All @@ -465,13 +465,13 @@ def add_documents_ndjson(
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
"""
return self.add_documents_raw(str_documents, primary_key, 'jsonl')
return self.add_documents_raw(str_documents, primary_key, 'application/x-ndjson')

def add_documents_raw(
self,
str_documents: str,
primary_key: Optional[str] = None,
doc_type: Optional[str] = None,
content_type: Optional[str] = None,
) -> Dict[str, int]:
"""Add string documents to the index.
Expand All @@ -496,12 +496,6 @@ def add_documents_raw(
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)
if doc_type == "json":
content_type = 'application/json'
if doc_type == "jsonl":
content_type = 'application/x-ndjson'
if doc_type == "csv":
content_type = 'text/csv'
return self.http.post(url, str_documents, content_type)

def update_documents(
Expand Down Expand Up @@ -1250,6 +1244,5 @@ def _build_url(
):
if primary_key is None:
return f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}'
else:
primary_key = urllib.parse.urlencode({'primaryKey': primary_key})
return f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{primary_key}'
primary_key = urllib.parse.urlencode({'primaryKey': primary_key})
return f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{primary_key}'

0 comments on commit dfb4f32

Please sign in to comment.