Skip to content

Commit d3f35fa

Browse files
bors[bot]Sajda Kabirsajdakabir
authored
Merge #654
654: added updateDocumentsCsv(string docs, string primaryKey) r=alallema a=sajdakabir # Pull Request ## Related issue Fixes #347 ## What does this PR do? - Adds handles for updating with CSV string. ## PR checklist Please check if your PR fulfills the following requirements: - [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [X] Have you read the contributing guidelines? - [X] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Sajda Kabir <[email protected]> Co-authored-by: sajda <[email protected]>
2 parents 5e98619 + 531fed2 commit d3f35fa

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

meilisearch/index.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,33 @@ def update_documents_json(
592592
"""
593593
return self.update_documents_raw(str_documents, primary_key, "application/json")
594594

595+
def update_documents_csv(
596+
self,
597+
str_documents: str,
598+
primary_key: Optional[str] = None,
599+
) -> TaskInfo:
600+
"""Update documents as a csv string in the index.
601+
602+
Parameters
603+
----------
604+
str_documents:
605+
String of document from a CSV file.
606+
primary_key (optional):
607+
The primary-key used in index. Ignored if already set up
608+
609+
Returns
610+
-------
611+
task_info:
612+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
613+
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
614+
615+
Raises
616+
------
617+
MeiliSearchApiError
618+
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
619+
"""
620+
return self.update_documents_raw(str_documents, primary_key, "text/csv")
621+
595622
def update_documents_raw(
596623
self,
597624
str_documents: str,

tests/index/test_index_document_meilisearch.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ def test_add_documents_csv(empty_index, songs_csv):
197197
assert index.get_primary_key() == "id"
198198

199199

200+
def test_update_documents_csv(index_with_documents, songs_csv):
201+
"""Tests updating a single document with csv string."""
202+
index = index_with_documents()
203+
response = index.update_documents_csv(songs_csv)
204+
assert isinstance(response, TaskInfo)
205+
assert response.task_uid is not None
206+
task = index.wait_for_task(response.task_uid)
207+
assert task.status == "succeeded"
208+
assert index.get_primary_key() == "id"
209+
210+
200211
def test_add_documents_json(empty_index, small_movies_json_file):
201212
"""Tests adding new documents to a clean index."""
202213
index = empty_index()

0 commit comments

Comments
 (0)