Skip to content

Commit dc98a1e

Browse files
authored
Merge branch 'main' into feat/add-embedders-settings
2 parents e515f29 + a90ddf8 commit dc98a1e

8 files changed

+112
-3
lines changed

Diff for: meilisearch/client.py

+27
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,33 @@ def multi_search(
252252
body={"queries": queries, "federation": federation},
253253
)
254254

255+
def update_documents_by_function(
256+
self, index_uid: str, queries: Dict[str, List[Dict[str, Any]]]
257+
) -> Dict[str, Any]:
258+
"""Update Documents by function
259+
Parameters
260+
----------
261+
index_uid:
262+
The index_uid where you want to update documents of.
263+
queries:
264+
List of dictionaries containing functions with or without filters that you want to use to update documents.
265+
266+
Returns
267+
-------
268+
task_info:
269+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
270+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
271+
272+
Raises
273+
------
274+
MeilisearchApiError
275+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
276+
"""
277+
return self.http.post(
278+
path=f"{self.config.paths.index}/{index_uid}/{self.config.paths.document}/{self.config.paths.edit}",
279+
body=dict(queries),
280+
)
281+
255282
def get_all_stats(self) -> Dict[str, Any]:
256283
"""Get all stats of Meilisearch
257284

Diff for: meilisearch/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Paths:
4444
search_cutoff_ms = "search-cutoff-ms"
4545
proximity_precision = "proximity-precision"
4646
localized_attributes = "localized-attributes"
47+
edit = "edit"
4748

4849
def __init__(
4950
self,

Diff for: meilisearch/models/key.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class _KeyBase(CamelBase):
1111
uid: str
1212
name: Optional[str] = None
13-
description: str
13+
description: Optional[str]
1414
actions: List[str]
1515
indexes: List[str]
1616
expires_at: Optional[datetime] = None

Diff for: meilisearch/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
__version__ = "0.34.0"
3+
__version__ = "0.34.1"
44

55

66
def qualified_version() -> str:

Diff for: tests/client/test_client_key_meilisearch.py

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ def test_create_keys_default(client, test_key_info):
4646
assert key.indexes == test_key_info["indexes"]
4747

4848

49+
def test_create_keys_without_desc(client, test_nondescript_key_info):
50+
"""Tests the creation of a key with no optional argument."""
51+
key = client.create_key(test_nondescript_key_info)
52+
print(key)
53+
54+
assert key.name == "keyWithoutDescription"
55+
assert key.description is None
56+
57+
4958
def test_create_keys_with_options(client, test_key_info):
5059
"""Tests the creation of a key with arguments."""
5160
key = client.create_key(
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from tests.common import INDEX_UID
4+
5+
6+
@pytest.mark.usefixtures("enable_edit_documents_by_function")
7+
def test_update_document_by_function(client, index_with_documents):
8+
"""Delete the document with id and update document title"""
9+
index_with_documents()
10+
response = client.update_documents_by_function(
11+
INDEX_UID,
12+
{"function": 'if doc.id == "522681" {doc = () } else {doc.title = `* ${doc.title} *`}'},
13+
)
14+
15+
assert isinstance(response, dict)
16+
assert isinstance(response["taskUid"], int)
17+
assert response["indexUid"] == INDEX_UID

Diff for: tests/conftest.py

+56
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from typing import Optional
44

5+
import requests
56
from pytest import fixture
67

78
import meilisearch
@@ -205,13 +206,68 @@ def test_key_info(client):
205206
pass
206207

207208

209+
@fixture(scope="function")
210+
def test_nondescript_key_info(client):
211+
key_info = {
212+
"name": "keyWithoutDescription",
213+
"actions": ["search"],
214+
"indexes": [common.INDEX_UID],
215+
"expiresAt": None,
216+
}
217+
218+
yield key_info
219+
220+
try:
221+
keys = client.get_keys().results
222+
key = next(x for x in keys if x.name == key_info["name"])
223+
client.delete_key(key.key)
224+
except MeilisearchApiError:
225+
pass
226+
except StopIteration:
227+
pass
228+
229+
208230
@fixture(scope="function")
209231
def get_private_key(client):
210232
keys = client.get_keys().results
211233
key = next(x for x in keys if "Default Search API" in x.name)
212234
return key
213235

214236

237+
@fixture
238+
def enable_vector_search():
239+
requests.patch(
240+
f"{common.BASE_URL}/experimental-features",
241+
headers={"Authorization": f"Bearer {common.MASTER_KEY}"},
242+
json={"vectorStore": True},
243+
timeout=10,
244+
)
245+
yield
246+
requests.patch(
247+
f"{common.BASE_URL}/experimental-features",
248+
headers={"Authorization": f"Bearer {common.MASTER_KEY}"},
249+
json={"vectorStore": False},
250+
timeout=10,
251+
)
252+
253+
254+
@fixture
255+
def enable_edit_documents_by_function():
256+
requests.patch(
257+
f"{common.BASE_URL}/experimental-features",
258+
headers={"Authorization": f"Bearer {common.MASTER_KEY}"},
259+
json={"editDocumentsByFunction": True},
260+
timeout=10,
261+
)
262+
yield
263+
requests.patch(
264+
f"{common.BASE_URL}/experimental-features",
265+
headers={"Authorization": f"Bearer {common.MASTER_KEY}"},
266+
json={"editDocumentsByFunction": False},
267+
timeout=10,
268+
)
269+
270+
215271
@fixture
216272
def new_embedders():
217273
return {

Diff for: tests/index/test_index_document_meilisearch.py

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def test_update_documents_json_custom_serializer(empty_index):
171171

172172

173173
def test_update_documents_raw_custom_serializer(empty_index):
174-
175174
documents = [
176175
{"id": uuid4(), "title": "test 1", "when": datetime.now()},
177176
{"id": uuid4(), "title": "Test 2", "when": datetime.now()},

0 commit comments

Comments
 (0)