Skip to content

Commit c6ca566

Browse files
meili-bors[bot]meili-botsanders41alallema
authored
Merge #797
797: Changes related to the next Meilisearch release (v1.3.0) r=alallema a=meili-bot Related to this issue: meilisearch/integration-guides#280 This PR: - gathers the changes related to the next Meilisearch release (v1.3.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v1.3.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.3.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Paul Sanders <[email protected]> Co-authored-by: Amélie <[email protected]>
2 parents 5ce1081 + b107c31 commit c6ca566

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

meilisearch/index.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def get_stats(self) -> IndexStats:
243243
stats = self.http.get(f"{self.config.paths.index}/{self.uid}/{self.config.paths.stat}")
244244
return IndexStats(stats)
245245

246+
@version_error_hint_message
246247
def search(self, query: str, opt_params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
247248
"""Search in the index.
248249
@@ -251,7 +252,13 @@ def search(self, query: str, opt_params: Optional[Dict[str, Any]] = None) -> Dic
251252
query:
252253
String containing the searched word(s)
253254
opt_params (optional):
254-
Dictionary containing optional query parameters
255+
Dictionary containing optional query parameters.
256+
Note: The vector parameter is only available in Meilisearch >= v1.3.0, and is experimental
257+
Meilisearch v1.3.0. In order to use this feature in Meilisearch v1.3.0 you first need to
258+
enable the feature by sending a PATCH request to /experimental-features with
259+
{ "vectoreStore": true }. Because this feature is experimental it may be removed or
260+
updated causing breaking changes in this library without a major version bump so use
261+
with caution.
255262
https://www.meilisearch.com/docs/reference/api/search#search-in-an-index
256263
257264
Returns

tests/conftest.py

Lines changed: 31 additions & 0 deletions
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
@@ -126,6 +127,19 @@ def index_maker(index_uid=common.INDEX_UID, documents=small_movies):
126127
return index_maker
127128

128129

130+
@fixture(scope="function")
131+
def index_with_documents_and_vectors(empty_index, small_movies):
132+
small_movies[0]["_vectors"] = [0.1, 0.2]
133+
134+
def index_maker(index_uid=common.INDEX_UID, documents=small_movies):
135+
index = empty_index(index_uid)
136+
task = index.add_documents(documents)
137+
index.wait_for_task(task.task_uid)
138+
return index
139+
140+
return index_maker
141+
142+
129143
@fixture(scope="function")
130144
def test_key(client):
131145
key_info = {
@@ -172,3 +186,20 @@ def get_private_key(client):
172186
keys = client.get_keys().results
173187
key = next(x for x in keys if "Default Search API" in x.name)
174188
return key
189+
190+
191+
@fixture
192+
def enable_vector_search():
193+
requests.patch(
194+
f"{common.BASE_URL}/experimental-features",
195+
headers={"Authorization": f"Bearer {common.MASTER_KEY}"},
196+
json={"vectorStore": True},
197+
timeout=10,
198+
)
199+
yield
200+
requests.patch(
201+
f"{common.BASE_URL}/experimental-features",
202+
headers={"Authorization": f"Bearer {common.MASTER_KEY}"},
203+
json={"vectorStore": False},
204+
timeout=10,
205+
)

tests/index/test_index_search_meilisearch.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# pylint: disable=invalid-name
22

3+
import pytest
4+
35

46
def test_basic_search(index_with_documents):
57
"""Tests search with a simple query."""
@@ -441,3 +443,27 @@ def test_custom_search_params_with_pagination_parameters_at_zero(index_with_docu
441443
assert response["totalPages"] is not None
442444
assert response["totalHits"] is not None
443445
assert "estimatedTotalHits" is not response
446+
447+
448+
def test_attributes_to_search_on_search(index_with_documents):
449+
response = index_with_documents().search(
450+
"How to Train Your Dragon", opt_params={"attributesToSearchOn": ["title", "overview"]}
451+
)
452+
assert response["hits"][0]["id"] == "166428"
453+
454+
455+
def test_attributes_to_search_on_search_no_match(index_with_documents):
456+
response = index_with_documents().search(
457+
"How to Train Your Dragon", opt_params={"attributesToSearchOn": ["id"]}
458+
)
459+
assert response["hits"] == []
460+
461+
462+
@pytest.mark.usefixtures("enable_vector_search")
463+
def test_vector_search(index_with_documents_and_vectors):
464+
response = index_with_documents_and_vectors().search(
465+
"How to Train Your Dragon", opt_params={"vector": [0.1, 0.2]}
466+
)
467+
468+
assert response["hits"][0]["id"] == "287947"
469+
assert response["vector"] == [0.1, 0.2]

0 commit comments

Comments
 (0)