Skip to content

Commit 17f1ecd

Browse files
authored
Merge branch 'main' into remote_fedarated_search
2 parents 7dcf7d0 + 39f8263 commit 17f1ecd

18 files changed

+668
-298
lines changed

.code-samples.meilisearch.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ typo_tolerance_guide_4: |-
360360
'twoTypos': 10
361361
}
362362
})
363+
typo_tolerance_guide_5: |-
364+
client.index('movies').update_typo_tolerance({
365+
'disableOnNumbers': True
366+
})
363367
search_parameter_guide_show_ranking_score_1: |-
364368
client.index('movies').search('dragon', {
365369
'showRankingScore': True
@@ -626,6 +630,12 @@ update_pagination_settings_1: |-
626630
client.index('books').update_pagination_settings({'maxTotalHits': 100})
627631
reset_pagination_settings_1: |-
628632
client.index('books').reset_pagination_settings()
633+
get_facet_search_settings_1: |-
634+
client.index('books').get_facet_search_settings()
635+
update_facet_search_settings_1: |-
636+
client.index('books').update_facet_search_settings(False)
637+
reset_facet_search_settings_1: |-
638+
client.index('books').reset_facet_search_settings()
629639
get_faceting_settings_1: |-
630640
client.index('books').get_faceting_settings()
631641
update_faceting_settings_1: |-
@@ -716,6 +726,12 @@ update_search_cutoff_1: |-
716726
client.index('movies').update_search_cutoff_ms(150)
717727
reset_search_cutoff_1: |-
718728
client.index('movies').reset_search_cutoff_ms()
729+
get_prefix_search_settings_1: |-
730+
client.index('books').get_prefix_search()
731+
update_prefix_search_settings_1: |-
732+
client.index('books').update_prefix_search(PrefixSearch.DISABLED)
733+
reset_prefix_search_settings_1: |-
734+
client.index('books').reset_prefix_search()
719735
get_proximity_precision_settings_1: |-
720736
client.index('books').get_proximity_precision()
721737
update_proximity_precision_settings_1: |-

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- trying
99
- staging
1010
- main
11+
merge_group:
1112

1213
jobs:
1314
integration_tests:

Pipfile.lock

Lines changed: 256 additions & 268 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.8"
2-
31
services:
42
package:
53
build: .

meilisearch/_httprequests.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
MeilisearchCommunicationError,
1313
MeilisearchTimeoutError,
1414
)
15-
from meilisearch.models.index import ProximityPrecision
15+
from meilisearch.models.index import PrefixSearch, ProximityPrecision
1616
from meilisearch.version import qualified_version
1717

1818

@@ -36,6 +36,7 @@ def send_request(
3636
Mapping[str, Any],
3737
Sequence[Mapping[str, Any]],
3838
List[str],
39+
bool,
3940
bytes,
4041
str,
4142
int,
@@ -67,7 +68,7 @@ def send_request(
6768
serialize_body = isinstance(body, dict) or body
6869
data = (
6970
json.dumps(body, cls=serializer)
70-
if serialize_body
71+
if isinstance(body, bool) or serialize_body
7172
else "" if body == "" else "null"
7273
)
7374

@@ -80,6 +81,16 @@ def send_request(
8081
raise MeilisearchTimeoutError(str(err)) from err
8182
except requests.exceptions.ConnectionError as err:
8283
raise MeilisearchCommunicationError(str(err)) from err
84+
except requests.exceptions.InvalidSchema as err:
85+
if "://" not in self.config.url:
86+
raise MeilisearchCommunicationError(
87+
f"""
88+
Invalid URL {self.config.url}, no scheme/protocol supplied.
89+
Did you mean https://{self.config.url}?
90+
"""
91+
) from err
92+
93+
raise MeilisearchCommunicationError(str(err)) from err
8394

8495
def get(self, path: str) -> Any:
8596
return self.send_request(requests.get, path)
@@ -114,9 +125,11 @@ def put(
114125
Mapping[str, Any],
115126
Sequence[Mapping[str, Any]],
116127
List[str],
128+
bool,
117129
bytes,
118130
str,
119131
int,
132+
PrefixSearch,
120133
ProximityPrecision,
121134
]
122135
] = None,

meilisearch/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Paths:
4242
swap = "swap-indexes"
4343
embedders = "embedders"
4444
search_cutoff_ms = "search-cutoff-ms"
45+
prefix_search = "prefix-search"
4546
proximity_precision = "proximity-precision"
4647
localized_attributes = "localized-attributes"
4748
edit = "edit"

meilisearch/index.py

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from meilisearch.errors import version_error_hint_message
2626
from meilisearch.models.document import Document, DocumentsResults
2727
from meilisearch.models.embedders import (
28+
CompositeEmbedder,
2829
Embedders,
2930
EmbedderType,
3031
HuggingFaceEmbedder,
@@ -38,6 +39,7 @@
3839
IndexStats,
3940
LocalizedAttributes,
4041
Pagination,
42+
PrefixSearch,
4143
ProximityPrecision,
4244
TypoTolerance,
4345
)
@@ -977,6 +979,8 @@ def get_settings(self) -> Dict[str, Any]:
977979
embedders[k] = HuggingFaceEmbedder(**v)
978980
elif v.get("source") == "rest":
979981
embedders[k] = RestEmbedder(**v)
982+
elif v.get("source") == "composite":
983+
embedders[k] = CompositeEmbedder(**v)
980984
else:
981985
embedders[k] = UserProvidedEmbedder(**v)
982986

@@ -1662,6 +1666,57 @@ def reset_pagination_settings(self) -> TaskInfo:
16621666

16631667
return TaskInfo(**task)
16641668

1669+
def get_facet_search_settings(self) -> bool:
1670+
"""Get the facet search settings of an index.
1671+
1672+
Returns
1673+
-------
1674+
bool:
1675+
True if facet search is enabled, False if disabled.
1676+
Raises
1677+
------
1678+
MeilisearchApiError
1679+
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
1680+
"""
1681+
1682+
return self.http.get(self.__settings_url_for(self.config.paths.facet_search))
1683+
1684+
def update_facet_search_settings(self, body: Union[bool, None]) -> TaskInfo:
1685+
"""Update the facet search settings of the index.
1686+
1687+
Parameters
1688+
----------
1689+
body: bool
1690+
True to enable facet search, False to disable it.
1691+
1692+
Returns
1693+
-------
1694+
task_info:
1695+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1696+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
1697+
1698+
Raises
1699+
------
1700+
MeilisearchApiError
1701+
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
1702+
"""
1703+
task = self.http.put(self.__settings_url_for(self.config.paths.facet_search), body=body)
1704+
1705+
return TaskInfo(**task)
1706+
1707+
def reset_facet_search_settings(self) -> TaskInfo:
1708+
"""Reset facet search settings of the index to default values.
1709+
1710+
Returns
1711+
-------
1712+
task_info:
1713+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1714+
https://www.meilisearch.com/docs/reference/api/tasks
1715+
"""
1716+
task = self.http.delete(self.__settings_url_for(self.config.paths.facet_search))
1717+
1718+
return TaskInfo(**task)
1719+
16651720
def get_faceting_settings(self) -> Faceting:
16661721
"""Get the faceting settings of an index.
16671722
@@ -1675,7 +1730,6 @@ def get_faceting_settings(self) -> Faceting:
16751730
MeilisearchApiError
16761731
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
16771732
"""
1678-
16791733
faceting = self.http.get(self.__settings_url_for(self.config.paths.faceting))
16801734

16811735
return Faceting(**faceting)
@@ -1934,6 +1988,8 @@ def get_embedders(self) -> Embedders | None:
19341988
embedders[k] = OllamaEmbedder(**v)
19351989
elif source == "rest":
19361990
embedders[k] = RestEmbedder(**v)
1991+
elif source == "composite":
1992+
embedders[k] = CompositeEmbedder(**v)
19371993
elif source == "userProvided":
19381994
embedders[k] = UserProvidedEmbedder(**v)
19391995
else:
@@ -1977,6 +2033,8 @@ def update_embedders(self, body: Union[MutableMapping[str, Any], None]) -> TaskI
19772033
embedders[k] = OllamaEmbedder(**v)
19782034
elif source == "rest":
19792035
embedders[k] = RestEmbedder(**v)
2036+
elif source == "composite":
2037+
embedders[k] = CompositeEmbedder(**v)
19802038
elif source == "userProvided":
19812039
embedders[k] = UserProvidedEmbedder(**v)
19822040
else:
@@ -2071,6 +2129,58 @@ def reset_search_cutoff_ms(self) -> TaskInfo:
20712129

20722130
return TaskInfo(**task)
20732131

2132+
# PREFIX SEARCH
2133+
2134+
def get_prefix_search(self) -> PrefixSearch:
2135+
"""Get the prefix search settings of an index.
2136+
2137+
Returns
2138+
-------
2139+
settings:
2140+
The prefix search settings of the index.
2141+
2142+
Raises
2143+
------
2144+
MeilisearchApiError
2145+
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
2146+
"""
2147+
prefix_search = self.http.get(self.__settings_url_for(self.config.paths.prefix_search))
2148+
2149+
return PrefixSearch[to_snake(prefix_search).upper()]
2150+
2151+
def update_prefix_search(self, body: Union[PrefixSearch, None]) -> TaskInfo:
2152+
"""Update the prefix search settings of the index.
2153+
2154+
Parameters
2155+
----------
2156+
body:
2157+
Prefix search settings
2158+
2159+
Returns
2160+
-------
2161+
task_info:
2162+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
2163+
https://www.meilisearch.com/docs/reference/api/tasks
2164+
"""
2165+
task = self.http.put(self.__settings_url_for(self.config.paths.prefix_search), body)
2166+
2167+
return TaskInfo(**task)
2168+
2169+
def reset_prefix_search(self) -> TaskInfo:
2170+
"""Reset the prefix search settings of the index
2171+
2172+
Returns
2173+
-------
2174+
task_info:
2175+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
2176+
https://www.meilisearch.com/docs/reference/api/tasks
2177+
"""
2178+
task = self.http.delete(
2179+
self.__settings_url_for(self.config.paths.prefix_search),
2180+
)
2181+
2182+
return TaskInfo(**task)
2183+
20742184
# PROXIMITY PRECISION SETTINGS
20752185

20762186
def get_proximity_precision(self) -> ProximityPrecision:

meilisearch/models/document.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33

44
class Document:
5-
__doc: Dict
6-
75
def __init__(self, doc: Dict[str, Any]) -> None:
8-
self.__doc = doc
9-
for key in doc:
10-
setattr(self, key, doc[key])
6+
self.__dict__.update(**doc)
117

12-
def __getattr__(self, attr: str) -> str:
13-
if attr in self.__doc.keys():
14-
return attr
8+
def __getattr__(self, attr: str) -> Any:
9+
if attr in self.__dict__:
10+
return self.__dict__[attr]
1511
raise AttributeError(f"{self.__class__.__name__} object has no attribute {attr}")
1612

1713
def __iter__(self) -> Iterator:

0 commit comments

Comments
 (0)