Skip to content

Commit 2349f34

Browse files
authored
Merge branch 'main' into bump-meilisearch-v1.0.0
2 parents 271f316 + 0b509dd commit 2349f34

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
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,

meilisearch/models/task.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

3-
from typing import Any, Dict, List, Union
3+
from datetime import datetime
4+
from typing import Any, Dict, List, Optional, Union
45

56
from camel_converter.pydantic_base import CamelBase
67

@@ -10,21 +11,21 @@ class Task(CamelBase):
1011
index_uid: Union[str, None]
1112
status: str
1213
type: str
13-
details: Dict[str, Any]
14+
details: Union[Dict[str, Any], None]
1415
error: Union[Dict[str, Any], None]
1516
canceled_by: Union[int, None]
16-
duration: str
17-
enqueued_at: str
18-
started_at: str
19-
finished_at: str
17+
duration: Optional[str]
18+
enqueued_at: datetime
19+
started_at: Optional[datetime]
20+
finished_at: Optional[datetime]
2021

2122

2223
class TaskInfo(CamelBase):
2324
task_uid: int
2425
index_uid: Union[str, None]
2526
status: str
2627
type: str
27-
enqueued_at: str
28+
enqueued_at: datetime
2829

2930

3031
class TaskResults:

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)