meilisearch-python-sdk 3.0.1__tar.gz → 3.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of meilisearch-python-sdk might be problematic. Click here for more details.
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/PKG-INFO +1 -1
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/_client.py +45 -10
- meilisearch_python_sdk-3.2.0/meilisearch_python_sdk/_version.py +1 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/index.py +60 -9
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/search.py +11 -9
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/pyproject.toml +4 -4
- meilisearch_python_sdk-3.0.1/meilisearch_python_sdk/_version.py +0 -1
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/LICENSE +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/README.md +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/__init__.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/_http_requests.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/_task.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/_utils.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/decorators.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/errors.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/json_handler.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/__init__.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/client.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/documents.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/health.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/index.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/settings.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/task.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/version.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/plugins.py +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/py.typed +0 -0
- {meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/types.py +0 -0
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/_client.py
RENAMED
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from datetime import datetime, timezone
|
|
4
4
|
from ssl import SSLContext
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
5
|
+
from typing import TYPE_CHECKING, Any
|
|
6
6
|
|
|
7
7
|
import jwt
|
|
8
8
|
from httpx import AsyncClient as HttpxAsyncClient
|
|
@@ -27,12 +27,13 @@ from meilisearch_python_sdk.models.settings import MeilisearchSettings
|
|
|
27
27
|
from meilisearch_python_sdk.models.task import TaskInfo, TaskResult, TaskStatus
|
|
28
28
|
from meilisearch_python_sdk.models.version import Version
|
|
29
29
|
from meilisearch_python_sdk.plugins import AsyncIndexPlugins, IndexPlugins
|
|
30
|
+
from meilisearch_python_sdk.types import JsonDict
|
|
30
31
|
|
|
31
32
|
if TYPE_CHECKING: # pragma: no cover
|
|
32
33
|
import sys
|
|
33
34
|
from types import TracebackType
|
|
34
35
|
|
|
35
|
-
from meilisearch_python_sdk.types import
|
|
36
|
+
from meilisearch_python_sdk.types import JsonMapping
|
|
36
37
|
|
|
37
38
|
if sys.version_info >= (3, 11):
|
|
38
39
|
from typing import Self
|
|
@@ -219,6 +220,7 @@ class AsyncClient(BaseClient):
|
|
|
219
220
|
wait: bool = True,
|
|
220
221
|
timeout_in_ms: int | None = None,
|
|
221
222
|
plugins: AsyncIndexPlugins | None = None,
|
|
223
|
+
hits_type: Any = JsonDict,
|
|
222
224
|
) -> AsyncIndex:
|
|
223
225
|
"""Creates a new index.
|
|
224
226
|
|
|
@@ -238,6 +240,8 @@ class AsyncClient(BaseClient):
|
|
|
238
240
|
MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
|
|
239
241
|
if the `None` option is used the wait time could be very long. Defaults to None.
|
|
240
242
|
plugins: Optional plugins can be provided to extend functionality.
|
|
243
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
244
|
+
JsonDict
|
|
241
245
|
|
|
242
246
|
Returns:
|
|
243
247
|
|
|
@@ -263,6 +267,7 @@ class AsyncClient(BaseClient):
|
|
|
263
267
|
timeout_in_ms=timeout_in_ms,
|
|
264
268
|
plugins=plugins,
|
|
265
269
|
json_handler=self.json_handler,
|
|
270
|
+
hits_type=hits_type,
|
|
266
271
|
)
|
|
267
272
|
|
|
268
273
|
async def create_snapshot(self) -> TaskInfo:
|
|
@@ -436,7 +441,12 @@ class AsyncClient(BaseClient):
|
|
|
436
441
|
return ClientStats(**response.json())
|
|
437
442
|
|
|
438
443
|
async def get_or_create_index(
|
|
439
|
-
self,
|
|
444
|
+
self,
|
|
445
|
+
uid: str,
|
|
446
|
+
primary_key: str | None = None,
|
|
447
|
+
*,
|
|
448
|
+
plugins: AsyncIndexPlugins | None = None,
|
|
449
|
+
hits_type: Any = JsonDict,
|
|
440
450
|
) -> AsyncIndex:
|
|
441
451
|
"""Get an index, or create it if it doesn't exist.
|
|
442
452
|
|
|
@@ -445,6 +455,8 @@ class AsyncClient(BaseClient):
|
|
|
445
455
|
uid: The index's unique identifier.
|
|
446
456
|
primary_key: The primary key of the documents. Defaults to None.
|
|
447
457
|
plugins: Optional plugins can be provided to extend functionality.
|
|
458
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
459
|
+
JsonDict
|
|
448
460
|
|
|
449
461
|
Returns:
|
|
450
462
|
|
|
@@ -467,7 +479,9 @@ class AsyncClient(BaseClient):
|
|
|
467
479
|
except MeilisearchApiError as err:
|
|
468
480
|
if "index_not_found" not in err.code:
|
|
469
481
|
raise
|
|
470
|
-
index_instance = await self.create_index(
|
|
482
|
+
index_instance = await self.create_index(
|
|
483
|
+
uid, primary_key, plugins=plugins, hits_type=hits_type
|
|
484
|
+
)
|
|
471
485
|
return index_instance
|
|
472
486
|
|
|
473
487
|
async def create_key(self, key: KeyCreate) -> Key:
|
|
@@ -618,12 +632,16 @@ class AsyncClient(BaseClient):
|
|
|
618
632
|
|
|
619
633
|
return Key(**response.json())
|
|
620
634
|
|
|
621
|
-
async def multi_search(
|
|
635
|
+
async def multi_search(
|
|
636
|
+
self, queries: list[SearchParams], *, hits_type: Any = JsonDict
|
|
637
|
+
) -> list[SearchResultsWithUID]:
|
|
622
638
|
"""Multi-index search.
|
|
623
639
|
|
|
624
640
|
Args:
|
|
625
641
|
|
|
626
642
|
queries: List of SearchParameters
|
|
643
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
644
|
+
JsonDict
|
|
627
645
|
|
|
628
646
|
Returns:
|
|
629
647
|
|
|
@@ -651,7 +669,7 @@ class AsyncClient(BaseClient):
|
|
|
651
669
|
body={"queries": [x.model_dump(by_alias=True) for x in queries]}, # type: ignore[attr-defined]
|
|
652
670
|
)
|
|
653
671
|
|
|
654
|
-
return [SearchResultsWithUID(**x) for x in response.json()["results"]]
|
|
672
|
+
return [SearchResultsWithUID[hits_type](**x) for x in response.json()["results"]]
|
|
655
673
|
|
|
656
674
|
async def get_raw_index(self, uid: str) -> IndexInfo | None:
|
|
657
675
|
"""Gets the index and returns all the index information rather than an AsyncIndex instance.
|
|
@@ -1083,6 +1101,7 @@ class Client(BaseClient):
|
|
|
1083
1101
|
wait: bool = True,
|
|
1084
1102
|
timeout_in_ms: int | None = None,
|
|
1085
1103
|
plugins: IndexPlugins | None = None,
|
|
1104
|
+
hits_type: Any = JsonDict,
|
|
1086
1105
|
) -> Index:
|
|
1087
1106
|
"""Creates a new index.
|
|
1088
1107
|
|
|
@@ -1102,6 +1121,8 @@ class Client(BaseClient):
|
|
|
1102
1121
|
MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
|
|
1103
1122
|
if the `None` option is used the wait time could be very long. Defaults to None.
|
|
1104
1123
|
plugins: Optional plugins can be provided to extend functionality.
|
|
1124
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
1125
|
+
JsonDict
|
|
1105
1126
|
|
|
1106
1127
|
Returns:
|
|
1107
1128
|
|
|
@@ -1127,6 +1148,7 @@ class Client(BaseClient):
|
|
|
1127
1148
|
timeout_in_ms=timeout_in_ms,
|
|
1128
1149
|
plugins=plugins,
|
|
1129
1150
|
json_handler=self.json_handler,
|
|
1151
|
+
hits_type=hits_type,
|
|
1130
1152
|
)
|
|
1131
1153
|
|
|
1132
1154
|
def create_snapshot(self) -> TaskInfo:
|
|
@@ -1296,7 +1318,12 @@ class Client(BaseClient):
|
|
|
1296
1318
|
return ClientStats(**response.json())
|
|
1297
1319
|
|
|
1298
1320
|
def get_or_create_index(
|
|
1299
|
-
self,
|
|
1321
|
+
self,
|
|
1322
|
+
uid: str,
|
|
1323
|
+
primary_key: str | None = None,
|
|
1324
|
+
*,
|
|
1325
|
+
plugins: IndexPlugins | None = None,
|
|
1326
|
+
hits_type: Any = JsonDict,
|
|
1300
1327
|
) -> Index:
|
|
1301
1328
|
"""Get an index, or create it if it doesn't exist.
|
|
1302
1329
|
|
|
@@ -1305,6 +1332,8 @@ class Client(BaseClient):
|
|
|
1305
1332
|
uid: The index's unique identifier.
|
|
1306
1333
|
primary_key: The primary key of the documents. Defaults to None.
|
|
1307
1334
|
plugins: Optional plugins can be provided to extend functionality.
|
|
1335
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
1336
|
+
JsonDict
|
|
1308
1337
|
|
|
1309
1338
|
Returns:
|
|
1310
1339
|
|
|
@@ -1327,7 +1356,9 @@ class Client(BaseClient):
|
|
|
1327
1356
|
except MeilisearchApiError as err:
|
|
1328
1357
|
if "index_not_found" not in err.code:
|
|
1329
1358
|
raise
|
|
1330
|
-
index_instance = self.create_index(
|
|
1359
|
+
index_instance = self.create_index(
|
|
1360
|
+
uid, primary_key, plugins=plugins, hits_type=hits_type
|
|
1361
|
+
)
|
|
1331
1362
|
return index_instance
|
|
1332
1363
|
|
|
1333
1364
|
def create_key(self, key: KeyCreate) -> Key:
|
|
@@ -1478,12 +1509,16 @@ class Client(BaseClient):
|
|
|
1478
1509
|
|
|
1479
1510
|
return Key(**response.json())
|
|
1480
1511
|
|
|
1481
|
-
def multi_search(
|
|
1512
|
+
def multi_search(
|
|
1513
|
+
self, queries: list[SearchParams], *, hits_type: Any = JsonDict
|
|
1514
|
+
) -> list[SearchResultsWithUID]:
|
|
1482
1515
|
"""Multi-index search.
|
|
1483
1516
|
|
|
1484
1517
|
Args:
|
|
1485
1518
|
|
|
1486
1519
|
queries: List of SearchParameters
|
|
1520
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
1521
|
+
JsonDict
|
|
1487
1522
|
|
|
1488
1523
|
Returns:
|
|
1489
1524
|
|
|
@@ -1511,7 +1546,7 @@ class Client(BaseClient):
|
|
|
1511
1546
|
body={"queries": [x.model_dump(by_alias=True) for x in queries]}, # type: ignore[attr-defined]
|
|
1512
1547
|
)
|
|
1513
1548
|
|
|
1514
|
-
return [SearchResultsWithUID(**x) for x in response.json()["results"]]
|
|
1549
|
+
return [SearchResultsWithUID[hits_type](**x) for x in response.json()["results"]]
|
|
1515
1550
|
|
|
1516
1551
|
def get_raw_index(self, uid: str) -> IndexInfo | None:
|
|
1517
1552
|
"""Gets the index and returns all the index information rather than an Index instance.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "3.2.0"
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/index.py
RENAMED
|
@@ -52,11 +52,12 @@ from meilisearch_python_sdk.plugins import (
|
|
|
52
52
|
Plugin,
|
|
53
53
|
PostSearchPlugin,
|
|
54
54
|
)
|
|
55
|
+
from meilisearch_python_sdk.types import JsonDict
|
|
55
56
|
|
|
56
57
|
if TYPE_CHECKING: # pragma: no cover
|
|
57
58
|
import sys
|
|
58
59
|
|
|
59
|
-
from meilisearch_python_sdk.types import Filter,
|
|
60
|
+
from meilisearch_python_sdk.types import Filter, JsonMapping
|
|
60
61
|
|
|
61
62
|
if sys.version_info >= (3, 11):
|
|
62
63
|
from typing import Self
|
|
@@ -72,11 +73,13 @@ class _BaseIndex:
|
|
|
72
73
|
created_at: str | datetime | None = None,
|
|
73
74
|
updated_at: str | datetime | None = None,
|
|
74
75
|
json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
|
|
76
|
+
hits_type: Any = JsonDict,
|
|
75
77
|
):
|
|
76
78
|
self.uid = uid
|
|
77
79
|
self.primary_key = primary_key
|
|
78
80
|
self.created_at: datetime | None = iso_to_date_time(created_at)
|
|
79
81
|
self.updated_at: datetime | None = iso_to_date_time(updated_at)
|
|
82
|
+
self.hits_type = hits_type
|
|
80
83
|
self._base_url = "indexes/"
|
|
81
84
|
self._base_url_with_uid = f"{self._base_url}{self.uid}"
|
|
82
85
|
self._documents_url = f"{self._base_url_with_uid}/documents"
|
|
@@ -113,6 +116,8 @@ class AsyncIndex(_BaseIndex):
|
|
|
113
116
|
updated_at: str | datetime | None = None,
|
|
114
117
|
plugins: AsyncIndexPlugins | None = None,
|
|
115
118
|
json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
|
|
119
|
+
*,
|
|
120
|
+
hits_type: Any = JsonDict,
|
|
116
121
|
):
|
|
117
122
|
"""Class initializer.
|
|
118
123
|
|
|
@@ -129,8 +134,17 @@ class AsyncIndex(_BaseIndex):
|
|
|
129
134
|
(uses the json module from the standard library), OrjsonHandler (uses orjson), or
|
|
130
135
|
UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
|
|
131
136
|
extra needs to be included. Default: BuiltinHandler.
|
|
137
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
138
|
+
JsonDict
|
|
132
139
|
"""
|
|
133
|
-
super().__init__(
|
|
140
|
+
super().__init__(
|
|
141
|
+
uid=uid,
|
|
142
|
+
primary_key=primary_key,
|
|
143
|
+
created_at=created_at,
|
|
144
|
+
updated_at=updated_at,
|
|
145
|
+
json_handler=json_handler,
|
|
146
|
+
hits_type=hits_type,
|
|
147
|
+
)
|
|
134
148
|
self.http_client = http_client
|
|
135
149
|
self._http_requests = AsyncHttpRequests(http_client, json_handler=self._json_handler)
|
|
136
150
|
self.plugins = plugins
|
|
@@ -639,6 +653,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
639
653
|
timeout_in_ms: int | None = None,
|
|
640
654
|
plugins: AsyncIndexPlugins | None = None,
|
|
641
655
|
json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
|
|
656
|
+
hits_type: Any = JsonDict,
|
|
642
657
|
) -> Self:
|
|
643
658
|
"""Creates a new index.
|
|
644
659
|
|
|
@@ -667,6 +682,8 @@ class AsyncIndex(_BaseIndex):
|
|
|
667
682
|
(uses the json module from the standard library), OrjsonHandler (uses orjson), or
|
|
668
683
|
UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
|
|
669
684
|
extra needs to be included. Default: BuiltinHandler.
|
|
685
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
686
|
+
JsonDict
|
|
670
687
|
|
|
671
688
|
Returns:
|
|
672
689
|
|
|
@@ -708,6 +725,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
708
725
|
updated_at=index_dict["updatedAt"],
|
|
709
726
|
plugins=plugins,
|
|
710
727
|
json_handler=json_handler,
|
|
728
|
+
hits_type=hits_type,
|
|
711
729
|
)
|
|
712
730
|
|
|
713
731
|
if settings:
|
|
@@ -763,6 +781,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
763
781
|
hits_per_page: int | None = None,
|
|
764
782
|
page: int | None = None,
|
|
765
783
|
attributes_to_search_on: list[str] | None = None,
|
|
784
|
+
distinct: str | None = None,
|
|
766
785
|
show_ranking_score: bool = False,
|
|
767
786
|
show_ranking_score_details: bool = False,
|
|
768
787
|
ranking_score_threshold: float | None = None,
|
|
@@ -797,6 +816,9 @@ class AsyncIndex(_BaseIndex):
|
|
|
797
816
|
page: Sets the specific results page to fetch.
|
|
798
817
|
attributes_to_search_on: List of field names. Allow search over a subset of searchable
|
|
799
818
|
attributes without modifying the index settings. Defaults to None.
|
|
819
|
+
distinct: If set the distinct value will return at most one result for the
|
|
820
|
+
filterable attribute. Note that a filterable attributes must be set for this work.
|
|
821
|
+
Defaults to None.
|
|
800
822
|
show_ranking_score: If set to True the ranking score will be returned with each document
|
|
801
823
|
in the search. Defaults to False.
|
|
802
824
|
show_ranking_score_details: If set to True the ranking details will be returned with
|
|
@@ -863,6 +885,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
863
885
|
hits_per_page=hits_per_page,
|
|
864
886
|
page=page,
|
|
865
887
|
attributes_to_search_on=attributes_to_search_on,
|
|
888
|
+
distinct=distinct,
|
|
866
889
|
show_ranking_score=show_ranking_score,
|
|
867
890
|
show_ranking_score_details=show_ranking_score_details,
|
|
868
891
|
vector=vector,
|
|
@@ -893,6 +916,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
893
916
|
hits_per_page=hits_per_page,
|
|
894
917
|
page=page,
|
|
895
918
|
attributes_to_search_on=attributes_to_search_on,
|
|
919
|
+
distinct=distinct,
|
|
896
920
|
show_ranking_score=show_ranking_score,
|
|
897
921
|
show_ranking_score_details=show_ranking_score_details,
|
|
898
922
|
vector=vector,
|
|
@@ -925,6 +949,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
925
949
|
hits_per_page=hits_per_page,
|
|
926
950
|
page=page,
|
|
927
951
|
attributes_to_search_on=attributes_to_search_on,
|
|
952
|
+
distinct=distinct,
|
|
928
953
|
show_ranking_score=show_ranking_score,
|
|
929
954
|
show_ranking_score_details=show_ranking_score_details,
|
|
930
955
|
vector=vector,
|
|
@@ -934,7 +959,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
934
959
|
concurrent_tasks.append(self._http_requests.post(search_url, body=body))
|
|
935
960
|
|
|
936
961
|
responses = await asyncio.gather(*concurrent_tasks)
|
|
937
|
-
result = SearchResults(**responses[-1].json())
|
|
962
|
+
result = SearchResults[self.hits_type](**responses[-1].json()) # type: ignore[name-defined]
|
|
938
963
|
if self._post_search_plugins:
|
|
939
964
|
post = await AsyncIndex._run_plugins(
|
|
940
965
|
self._post_search_plugins, AsyncEvent.POST, search_results=result
|
|
@@ -968,6 +993,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
968
993
|
hits_per_page=hits_per_page,
|
|
969
994
|
page=page,
|
|
970
995
|
attributes_to_search_on=attributes_to_search_on,
|
|
996
|
+
distinct=distinct,
|
|
971
997
|
show_ranking_score=show_ranking_score,
|
|
972
998
|
show_ranking_score_details=show_ranking_score_details,
|
|
973
999
|
vector=vector,
|
|
@@ -977,7 +1003,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
977
1003
|
response_coroutine = tg.create_task(self._http_requests.post(search_url, body=body))
|
|
978
1004
|
|
|
979
1005
|
response = await response_coroutine
|
|
980
|
-
result = SearchResults(**response.json())
|
|
1006
|
+
result = SearchResults[self.hits_type](**response.json()) # type: ignore[name-defined]
|
|
981
1007
|
if self._post_search_plugins:
|
|
982
1008
|
post = await AsyncIndex._run_plugins(
|
|
983
1009
|
self._post_search_plugins, AsyncEvent.POST, search_results=result
|
|
@@ -988,7 +1014,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
988
1014
|
return result
|
|
989
1015
|
|
|
990
1016
|
response = await self._http_requests.post(search_url, body=body)
|
|
991
|
-
result = SearchResults(**response.json())
|
|
1017
|
+
result = SearchResults[self.hits_type](**response.json()) # type: ignore[name-defined]
|
|
992
1018
|
|
|
993
1019
|
if self._post_search_plugins:
|
|
994
1020
|
post = await AsyncIndex._run_plugins(
|
|
@@ -1324,7 +1350,7 @@ class AsyncIndex(_BaseIndex):
|
|
|
1324
1350
|
f"{self._base_url_with_uid}/similar", body=payload
|
|
1325
1351
|
)
|
|
1326
1352
|
|
|
1327
|
-
return SimilarSearchResults(**response.json())
|
|
1353
|
+
return SimilarSearchResults[self.hits_type](**response.json()) # type: ignore[name-defined]
|
|
1328
1354
|
|
|
1329
1355
|
async def get_document(self, document_id: str) -> JsonDict:
|
|
1330
1356
|
"""Get one document with given document identifier.
|
|
@@ -4516,6 +4542,8 @@ class Index(_BaseIndex):
|
|
|
4516
4542
|
updated_at: str | datetime | None = None,
|
|
4517
4543
|
plugins: IndexPlugins | None = None,
|
|
4518
4544
|
json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
|
|
4545
|
+
*,
|
|
4546
|
+
hits_type: Any = JsonDict,
|
|
4519
4547
|
):
|
|
4520
4548
|
"""Class initializer.
|
|
4521
4549
|
|
|
@@ -4532,8 +4560,17 @@ class Index(_BaseIndex):
|
|
|
4532
4560
|
(uses the json module from the standard library), OrjsonHandler (uses orjson), or
|
|
4533
4561
|
UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
|
|
4534
4562
|
extra needs to be included. Default: BuiltinHandler.
|
|
4563
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
4564
|
+
JsonDict
|
|
4535
4565
|
"""
|
|
4536
|
-
super().__init__(
|
|
4566
|
+
super().__init__(
|
|
4567
|
+
uid=uid,
|
|
4568
|
+
primary_key=primary_key,
|
|
4569
|
+
created_at=created_at,
|
|
4570
|
+
updated_at=updated_at,
|
|
4571
|
+
json_handler=json_handler,
|
|
4572
|
+
hits_type=hits_type,
|
|
4573
|
+
)
|
|
4537
4574
|
self.http_client = http_client
|
|
4538
4575
|
self._http_requests = HttpRequests(http_client, json_handler=self._json_handler)
|
|
4539
4576
|
self.plugins = plugins
|
|
@@ -4916,6 +4953,7 @@ class Index(_BaseIndex):
|
|
|
4916
4953
|
timeout_in_ms: int | None = None,
|
|
4917
4954
|
plugins: IndexPlugins | None = None,
|
|
4918
4955
|
json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
|
|
4956
|
+
hits_type: Any = JsonDict,
|
|
4919
4957
|
) -> Self:
|
|
4920
4958
|
"""Creates a new index.
|
|
4921
4959
|
|
|
@@ -4944,6 +4982,8 @@ class Index(_BaseIndex):
|
|
|
4944
4982
|
(uses the json module from the standard library), OrjsonHandler (uses orjson), or
|
|
4945
4983
|
UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
|
|
4946
4984
|
extra needs to be included. Default: BuiltinHandler.
|
|
4985
|
+
hits_type: Allows for a custom type to be passed to use for hits. Defaults to
|
|
4986
|
+
JsonDict
|
|
4947
4987
|
|
|
4948
4988
|
Returns:
|
|
4949
4989
|
|
|
@@ -4980,6 +5020,7 @@ class Index(_BaseIndex):
|
|
|
4980
5020
|
updated_at=index_dict["updatedAt"],
|
|
4981
5021
|
plugins=plugins,
|
|
4982
5022
|
json_handler=json_handler,
|
|
5023
|
+
hits_type=hits_type,
|
|
4983
5024
|
)
|
|
4984
5025
|
|
|
4985
5026
|
if settings:
|
|
@@ -5033,6 +5074,7 @@ class Index(_BaseIndex):
|
|
|
5033
5074
|
hits_per_page: int | None = None,
|
|
5034
5075
|
page: int | None = None,
|
|
5035
5076
|
attributes_to_search_on: list[str] | None = None,
|
|
5077
|
+
distinct: str | None = None,
|
|
5036
5078
|
show_ranking_score: bool = False,
|
|
5037
5079
|
show_ranking_score_details: bool = False,
|
|
5038
5080
|
ranking_score_threshold: float | None = None,
|
|
@@ -5067,6 +5109,9 @@ class Index(_BaseIndex):
|
|
|
5067
5109
|
page: Sets the specific results page to fetch.
|
|
5068
5110
|
attributes_to_search_on: List of field names. Allow search over a subset of searchable
|
|
5069
5111
|
attributes without modifying the index settings. Defaults to None.
|
|
5112
|
+
distinct: If set the distinct value will return at most one result for the
|
|
5113
|
+
filterable attribute. Note that a filterable attributes must be set for this work.
|
|
5114
|
+
Defaults to None.
|
|
5070
5115
|
show_ranking_score: If set to True the ranking score will be returned with each document
|
|
5071
5116
|
in the search. Defaults to False.
|
|
5072
5117
|
show_ranking_score_details: If set to True the ranking details will be returned with
|
|
@@ -5133,6 +5178,7 @@ class Index(_BaseIndex):
|
|
|
5133
5178
|
hits_per_page=hits_per_page,
|
|
5134
5179
|
page=page,
|
|
5135
5180
|
attributes_to_search_on=attributes_to_search_on,
|
|
5181
|
+
distinct=distinct,
|
|
5136
5182
|
show_ranking_score=show_ranking_score,
|
|
5137
5183
|
show_ranking_score_details=show_ranking_score_details,
|
|
5138
5184
|
vector=vector,
|
|
@@ -5162,6 +5208,7 @@ class Index(_BaseIndex):
|
|
|
5162
5208
|
hits_per_page=hits_per_page,
|
|
5163
5209
|
page=page,
|
|
5164
5210
|
attributes_to_search_on=attributes_to_search_on,
|
|
5211
|
+
distinct=distinct,
|
|
5165
5212
|
show_ranking_score=show_ranking_score,
|
|
5166
5213
|
show_ranking_score_details=show_ranking_score_details,
|
|
5167
5214
|
vector=vector,
|
|
@@ -5169,7 +5216,7 @@ class Index(_BaseIndex):
|
|
|
5169
5216
|
)
|
|
5170
5217
|
|
|
5171
5218
|
response = self._http_requests.post(f"{self._base_url_with_uid}/search", body=body)
|
|
5172
|
-
result = SearchResults(**response.json())
|
|
5219
|
+
result = SearchResults[self.hits_type](**response.json()) # type: ignore[name-defined]
|
|
5173
5220
|
if self._post_search_plugins:
|
|
5174
5221
|
post = Index._run_plugins(self._post_search_plugins, Event.POST, search_results=result)
|
|
5175
5222
|
if post.get("search_result"):
|
|
@@ -5408,7 +5455,7 @@ class Index(_BaseIndex):
|
|
|
5408
5455
|
|
|
5409
5456
|
response = self._http_requests.post(f"{self._base_url_with_uid}/similar", body=payload)
|
|
5410
5457
|
|
|
5411
|
-
return SimilarSearchResults(**response.json())
|
|
5458
|
+
return SimilarSearchResults[self.hits_type](**response.json()) # type: ignore[name-defined]
|
|
5412
5459
|
|
|
5413
5460
|
def get_document(self, document_id: str) -> JsonDict:
|
|
5414
5461
|
"""Get one document with given document identifier.
|
|
@@ -8204,6 +8251,7 @@ def _process_search_parameters(
|
|
|
8204
8251
|
hits_per_page: int | None = None,
|
|
8205
8252
|
page: int | None = None,
|
|
8206
8253
|
attributes_to_search_on: list[str] | None = None,
|
|
8254
|
+
distinct: str | None = None,
|
|
8207
8255
|
show_ranking_score: bool = False,
|
|
8208
8256
|
show_ranking_score_details: bool = False,
|
|
8209
8257
|
ranking_score_threshold: float | None = None,
|
|
@@ -8242,6 +8290,9 @@ def _process_search_parameters(
|
|
|
8242
8290
|
if facet_query:
|
|
8243
8291
|
body["facetQuery"] = facet_query
|
|
8244
8292
|
|
|
8293
|
+
if distinct:
|
|
8294
|
+
body["distinct"] = distinct
|
|
8295
|
+
|
|
8245
8296
|
if show_ranking_score_details:
|
|
8246
8297
|
body["showRankingScoreDetails"] = show_ranking_score_details
|
|
8247
8298
|
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Literal
|
|
3
|
+
from typing import Generic, Literal, TypeVar
|
|
4
4
|
|
|
5
|
-
import pydantic
|
|
6
5
|
from camel_converter.pydantic_base import CamelBase
|
|
6
|
+
from pydantic import Field, field_validator
|
|
7
7
|
|
|
8
8
|
from meilisearch_python_sdk.errors import MeilisearchError
|
|
9
9
|
from meilisearch_python_sdk.types import Filter, JsonDict
|
|
10
10
|
|
|
11
|
+
T = TypeVar("T")
|
|
12
|
+
|
|
11
13
|
|
|
12
14
|
class FacetHits(CamelBase):
|
|
13
15
|
value: str
|
|
@@ -27,7 +29,7 @@ class Hybrid(CamelBase):
|
|
|
27
29
|
|
|
28
30
|
class SearchParams(CamelBase):
|
|
29
31
|
index_uid: str
|
|
30
|
-
query: str | None =
|
|
32
|
+
query: str | None = Field(None, alias="q")
|
|
31
33
|
offset: int = 0
|
|
32
34
|
limit: int = 20
|
|
33
35
|
filter: Filter | None = None
|
|
@@ -51,7 +53,7 @@ class SearchParams(CamelBase):
|
|
|
51
53
|
vector: list[float] | None = None
|
|
52
54
|
hybrid: Hybrid | None = None
|
|
53
55
|
|
|
54
|
-
@
|
|
56
|
+
@field_validator("ranking_score_threshold", mode="before") # type: ignore[attr-defined]
|
|
55
57
|
@classmethod
|
|
56
58
|
def validate_ranking_score_threshold(cls, v: float | None) -> float | None:
|
|
57
59
|
if v and not 0.0 <= v <= 1.0:
|
|
@@ -60,8 +62,8 @@ class SearchParams(CamelBase):
|
|
|
60
62
|
return v
|
|
61
63
|
|
|
62
64
|
|
|
63
|
-
class SearchResults(CamelBase):
|
|
64
|
-
hits: list[
|
|
65
|
+
class SearchResults(CamelBase, Generic[T]):
|
|
66
|
+
hits: list[T]
|
|
65
67
|
offset: int | None = None
|
|
66
68
|
limit: int | None = None
|
|
67
69
|
estimated_total_hits: int | None = None
|
|
@@ -75,12 +77,12 @@ class SearchResults(CamelBase):
|
|
|
75
77
|
semantic_hit_count: int | None = None
|
|
76
78
|
|
|
77
79
|
|
|
78
|
-
class SearchResultsWithUID(SearchResults):
|
|
80
|
+
class SearchResultsWithUID(SearchResults, Generic[T]):
|
|
79
81
|
index_uid: str
|
|
80
82
|
|
|
81
83
|
|
|
82
|
-
class SimilarSearchResults(CamelBase):
|
|
83
|
-
hits: list[
|
|
84
|
+
class SimilarSearchResults(CamelBase, Generic[T]):
|
|
85
|
+
hits: list[T]
|
|
84
86
|
id: str
|
|
85
87
|
processing_time_ms: int
|
|
86
88
|
limit: int | None = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "meilisearch-python-sdk"
|
|
3
|
-
version = "3.0
|
|
3
|
+
version = "3.2.0"
|
|
4
4
|
description = "A Python client providing both async and sync support for the Meilisearch API"
|
|
5
5
|
authors = ["Paul Sanders <psanders1@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -40,15 +40,15 @@ all = ["orjson", "ujson"]
|
|
|
40
40
|
|
|
41
41
|
[tool.poetry.group.dev.dependencies]
|
|
42
42
|
mkdocs = "1.6.0"
|
|
43
|
-
mkdocs-material = "9.5.
|
|
43
|
+
mkdocs-material = "9.5.31"
|
|
44
44
|
mkdocstrings = {version = "0.25.2", extras = ["python"]}
|
|
45
|
-
mypy = "1.11.
|
|
45
|
+
mypy = "1.11.1"
|
|
46
46
|
pre-commit = "3.8.0"
|
|
47
47
|
pytest = "8.3.2"
|
|
48
48
|
pytest-cov = "5.0.0"
|
|
49
49
|
pytest-asyncio = "0.23.8"
|
|
50
50
|
pytest-xdist = "3.6.1"
|
|
51
|
-
ruff = "0.
|
|
51
|
+
ruff = "0.6.1"
|
|
52
52
|
tomli = {version = "2.0.1", python = "<3.11"}
|
|
53
53
|
types-aiofiles = "24.1.0.20240626"
|
|
54
54
|
typing-extensions = "4.12.2"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = "3.0.1"
|
|
File without changes
|
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/_task.py
RENAMED
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/_utils.py
RENAMED
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/decorators.py
RENAMED
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/errors.py
RENAMED
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/json_handler.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/index.py
RENAMED
|
File without changes
|
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/models/task.py
RENAMED
|
File without changes
|
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/plugins.py
RENAMED
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/py.typed
RENAMED
|
File without changes
|
{meilisearch_python_sdk-3.0.1 → meilisearch_python_sdk-3.2.0}/meilisearch_python_sdk/types.py
RENAMED
|
File without changes
|