Skip to content

Commit afa7bb3

Browse files
bors[bot]meili-botalallema
authored
Merge #318
318: Changes related to the next MeiliSearch release (v0.22.0) r=alallema a=meili-bot Related to this issue: meilisearch/integration-guides#139 This PR: - gathers the changes related to the next MeiliSearch release (v0.22.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 v0.22.0 is out. ⚠️ This PR should NOT be merged until the next release of MeiliSearch (v0.22.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: alallema <[email protected]> Co-authored-by: Amélie <[email protected]>
2 parents 785178f + 4498356 commit afa7bb3

8 files changed

+251
-7
lines changed

.code-samples.meilisearch.yaml

+48-6
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ update_settings_1: |-
5454
'typo',
5555
'proximity',
5656
'attribute',
57+
'sort',
5758
'exactness',
58-
'desc(release_date)',
59-
'desc(rank)'
59+
'release_date:desc',
60+
'rank:desc'
6061
],
6162
'distinctAttribute': 'movie_id',
6263
'searchableAttributes': [
@@ -70,6 +71,10 @@ update_settings_1: |-
7071
'genre',
7172
'release_date'
7273
],
74+
'sortableAttributes': [
75+
'title',
76+
'release_date'
77+
],
7378
'stopWords': [
7479
'the',
7580
'a',
@@ -107,9 +112,10 @@ update_ranking_rules_1: |-
107112
'typo',
108113
'proximity',
109114
'attribute',
115+
'sort',
110116
'exactness',
111-
'asc(release_date)',
112-
'desc(rank)'
117+
'release_date:asc',
118+
'rank:desc'
113119
])
114120
reset_ranking_rules_1: |-
115121
client.index('movies').reset_ranking_rules()
@@ -149,6 +155,15 @@ update_displayed_attributes_1: |-
149155
])
150156
reset_displayed_attributes_1: |-
151157
client.index('movies').reset_displayed_attributes()
158+
get_sortable_attributes_1: |-
159+
client.index('books').get_sortable_attributes()
160+
update_sortable_attributes_1: |-
161+
client.index('books').update_sortable_attributes([
162+
'price',
163+
'author'
164+
])
165+
reset_sortable_attributes_1: |-
166+
client.index('books').reset_sortable_attributes()
152167
get_index_stats_1: |-
153168
client.index('movies').get_stats()
154169
get_indexes_stats_1: |-
@@ -247,9 +262,10 @@ settings_guide_ranking_rules_1: |-
247262
'typo',
248263
'proximity',
249264
'attribute',
265+
'sort',
250266
'exactness',
251-
'asc(release_date)',
252-
'desc(rank)'
267+
'release_date:asc',
268+
'rank:desc'
253269
]
254270
})
255271
settings_guide_distinct_1: |-
@@ -350,3 +366,29 @@ get_dump_status_1: |-
350366
client.get_dump_status('20201101-110357260')
351367
phrase_search_1: |-
352368
client.index('movies').search('"african american" horror')
369+
sorting_guide_update_sortable_attributes_1: |-
370+
client.index('books').update_sortable_attributes([
371+
'author',
372+
'price'
373+
])
374+
sorting_guide_update_ranking_rules_1: |-
375+
client.index('books').update_ranking_rules([
376+
'words',
377+
'sort',
378+
'typo',
379+
'proximity',
380+
'attribute',
381+
'exactness'
382+
])
383+
sorting_guide_sort_parameter_1: |-
384+
client.index('books').search('science fiction', {
385+
'sort': ['price:asc']
386+
})
387+
sorting_guide_sort_parameter_2: |-
388+
client.index('books').search('butler', {
389+
'sort': ['author:desc']
390+
})
391+
search_parameter_guide_sort_1: |-
392+
client.index('books').search('science fiction', {
393+
'sort': ['price:asc']
394+
})

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ JSON output:
147147

148148
## 🤖 Compatibility with MeiliSearch
149149

150-
This package only guarantees the compatibility with the [version v0.21.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.21.0).
150+
This package only guarantees the compatibility with the [version v0.22.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.22.0).
151151

152152
## 💡 Learn More
153153

meilisearch/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Paths():
2424
synonyms = 'synonyms'
2525
accept_new_fields = 'accept-new-fields'
2626
filterable_attributes = 'filterable-attributes'
27+
sortable_attributes = 'sortable-attributes'
2728
dumps = 'dumps'
2829

2930
def __init__(

meilisearch/index.py

+64
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,70 @@ def reset_filterable_attributes(self) -> Dict[str, int]:
10361036
self.__settings_url_for(self.config.paths.filterable_attributes),
10371037
)
10381038

1039+
1040+
# SORTABLE ATTRIBUTES SUB-ROUTES
1041+
1042+
def get_sortable_attributes(self) -> List[str]:
1043+
"""
1044+
Get sortable attributes of the index.
1045+
1046+
Returns
1047+
-------
1048+
settings:
1049+
List containing the sortable attributes of the index
1050+
1051+
Raises
1052+
------
1053+
MeiliSearchApiError
1054+
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
1055+
"""
1056+
return self.http.get(
1057+
self.__settings_url_for(self.config.paths.sortable_attributes)
1058+
)
1059+
1060+
def update_sortable_attributes(self, body: List[str]) -> Dict[str, int]:
1061+
"""
1062+
Update sortable attributes of the index.
1063+
1064+
Parameters
1065+
----------
1066+
body:
1067+
List containing the sortable attributes.
1068+
1069+
Returns
1070+
-------
1071+
update:
1072+
Dictionary containing an update id to track the action:
1073+
https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status
1074+
1075+
Raises
1076+
------
1077+
MeiliSearchApiError
1078+
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
1079+
"""
1080+
return self.http.post(
1081+
self.__settings_url_for(self.config.paths.sortable_attributes),
1082+
body
1083+
)
1084+
1085+
def reset_sortable_attributes(self) -> Dict[str, int]:
1086+
"""Reset sortable attributes of the index to default values.
1087+
1088+
Returns
1089+
-------
1090+
update:
1091+
Dictionary containing an update id to track the action:
1092+
https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status
1093+
1094+
Raises
1095+
------
1096+
MeiliSearchApiError
1097+
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
1098+
"""
1099+
return self.http.delete(
1100+
self.__settings_url_for(self.config.paths.sortable_attributes),
1101+
)
1102+
10391103
@staticmethod
10401104
def _batch(
10411105
documents: List[Dict[str, Any]], batch_size: int

meilisearch/tests/index/test_index_search_meilisearch.py

+78
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,84 @@ def test_custom_search_params_with_many_params(index_with_documents):
215215
assert 'release_date' not in response['hits'][0]
216216
assert response['hits'][0]['title'] == 'Avengers: Infinity War'
217217

218+
def test_custom_search_params_with_sort_string(index_with_documents):
219+
index = index_with_documents()
220+
response = index.update_ranking_rules([
221+
'words',
222+
'typo',
223+
'sort',
224+
'proximity',
225+
'attribute',
226+
'exactness'
227+
])
228+
index.wait_for_pending_update(response['updateId'])
229+
update = index.update_sortable_attributes(['title'])
230+
index.wait_for_pending_update(update['updateId'])
231+
response = index.search(
232+
'world',
233+
{
234+
'sort': ['title:asc']
235+
}
236+
)
237+
assert isinstance(response, dict)
238+
assert len(response['hits']) == 12
239+
assert 'facetsDistribution' not in response
240+
assert 'exhaustiveFacetsCount' not in response
241+
assert response['hits'][0]['title'] == 'Alita: Battle Angel'
242+
assert response['hits'][1]['title'] == 'Aquaman'
243+
244+
def test_custom_search_params_with_sort_int(index_with_documents):
245+
index = index_with_documents()
246+
response = index.update_ranking_rules([
247+
'words',
248+
'typo',
249+
'sort',
250+
'proximity',
251+
'attribute',
252+
'exactness'
253+
])
254+
index.wait_for_pending_update(response['updateId'])
255+
update = index.update_sortable_attributes(['release_date'])
256+
index.wait_for_pending_update(update['updateId'])
257+
response = index.search(
258+
'world',
259+
{
260+
'sort': ['release_date:asc']
261+
}
262+
)
263+
assert isinstance(response, dict)
264+
assert len(response['hits']) == 12
265+
assert 'facetsDistribution' not in response
266+
assert 'exhaustiveFacetsCount' not in response
267+
assert response['hits'][0]['title'] == 'Avengers: Infinity War'
268+
assert response['hits'][1]['title'] == 'Redcon-1'
269+
270+
def test_custom_search_params_with_multiple_sort(index_with_documents):
271+
index = index_with_documents()
272+
response = index.update_ranking_rules([
273+
'words',
274+
'typo',
275+
'sort',
276+
'proximity',
277+
'attribute',
278+
'exactness'
279+
])
280+
index.wait_for_pending_update(response['updateId'])
281+
update = index.update_sortable_attributes(['title', 'release_date'])
282+
index.wait_for_pending_update(update['updateId'])
283+
response = index.search(
284+
'world',
285+
{
286+
'sort': ['title:asc', 'release_date:asc']
287+
}
288+
)
289+
assert isinstance(response, dict)
290+
assert len(response['hits']) == 12
291+
assert 'facetsDistribution' not in response
292+
assert 'exhaustiveFacetsCount' not in response
293+
assert response['hits'][0]['title'] == 'Alita: Battle Angel'
294+
assert response['hits'][1]['title'] == 'Aquaman'
295+
218296
def test_phrase_search(index_with_documents):
219297
response = index_with_documents().search('coco "dumbo"')
220298
assert isinstance(response, dict)

meilisearch/tests/settings/test_settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'typo',
1010
'proximity',
1111
'attribute',
12+
'sort',
1213
'exactness'
1314
]
1415

meilisearch/tests/settings/test_settings_ranking_rules_meilisearch.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'typo',
66
'proximity',
77
'attribute',
8+
'sort',
89
'exactness'
910
]
1011

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# pylint: disable=invalid-name
2+
3+
SORTABLE_ATTRIBUTES = ['title', 'release_date']
4+
5+
def test_get_sortable_attributes(empty_index):
6+
"""Tests getting the sortable attributes."""
7+
response = empty_index().get_sortable_attributes()
8+
assert isinstance(response, list)
9+
assert response == []
10+
11+
def test_update_sortable_attributes(empty_index):
12+
"""Tests updating the sortable attributes."""
13+
index = empty_index()
14+
response = index.update_sortable_attributes(SORTABLE_ATTRIBUTES)
15+
index.wait_for_pending_update(response['updateId'])
16+
get_attributes = index.get_sortable_attributes()
17+
assert len(get_attributes) == len(SORTABLE_ATTRIBUTES)
18+
for attribute in SORTABLE_ATTRIBUTES:
19+
assert attribute in get_attributes
20+
21+
def test_update_sortable_attributes_to_none(empty_index):
22+
"""Tests updating the sortable attributes at null."""
23+
index = empty_index()
24+
# Update the settings first
25+
response = index.update_sortable_attributes(SORTABLE_ATTRIBUTES)
26+
update = index.wait_for_pending_update(response['updateId'])
27+
assert update['status'] == 'processed'
28+
# Check the settings have been correctly updated
29+
get_attributes = index.get_sortable_attributes()
30+
for attribute in SORTABLE_ATTRIBUTES:
31+
assert attribute in get_attributes
32+
# Launch test to update at null the setting
33+
response = index.update_sortable_attributes(None)
34+
index.wait_for_pending_update(response['updateId'])
35+
response = index.get_sortable_attributes()
36+
assert response == []
37+
38+
def test_reset_sortable_attributes(empty_index):
39+
"""Tests resetting the sortable attributes setting to its default value"""
40+
index = empty_index()
41+
# Update the settings first
42+
response = index.update_sortable_attributes(SORTABLE_ATTRIBUTES)
43+
update = index.wait_for_pending_update(response['updateId'])
44+
assert update['status'] == 'processed'
45+
# Check the settings have been correctly updated
46+
get_attributes = index.get_sortable_attributes()
47+
assert len(get_attributes) == len(SORTABLE_ATTRIBUTES)
48+
for attribute in SORTABLE_ATTRIBUTES:
49+
assert attribute in get_attributes
50+
# Check the reset of the settings
51+
response = index.reset_sortable_attributes()
52+
assert isinstance(response, dict)
53+
assert 'updateId' in response
54+
index.wait_for_pending_update(response['updateId'])
55+
response = index.get_sortable_attributes()
56+
assert isinstance(response, list)
57+
assert response == []

0 commit comments

Comments
 (0)