Skip to content

Commit 43bdbae

Browse files
bors[bot]meili-botcurquiza
authored
Merge #210
210: Changes related to the next MeiliSearch release (v0.22.0) r=curquiza 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: Clémentine Urquizar <[email protected]>
2 parents 362dd8e + e9b6037 commit 43bdbae

File tree

8 files changed

+231
-23
lines changed

8 files changed

+231
-23
lines changed

.code-samples.meilisearch.yaml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ update_settings_1: |-
5858
'typo',
5959
'proximity',
6060
'attribute',
61+
'sort',
6162
'exactness',
62-
'desc(release_date)',
63-
'desc(rank)'
63+
'release_date:desc',
64+
'rank:desc'
6465
],
6566
distinctAttribute: 'movie_id',
6667
searchableAttributes: [
@@ -79,6 +80,10 @@ update_settings_1: |-
7980
'a',
8081
'an'
8182
],
83+
sortableAttributes: [
84+
'title',
85+
'release_date'
86+
],
8287
synonyms: {
8388
wolverine: ['xmen', 'logan'],
8489
logan: ['wolverine']
@@ -110,9 +115,10 @@ update_ranking_rules_1: |-
110115
'typo',
111116
'proximity',
112117
'attribute',
118+
'sort',
113119
'exactness',
114-
'asc(release_date)',
115-
'desc(rank)'
120+
'release_date:asc',
121+
'rank:desc'
116122
])
117123
reset_ranking_rules_1: |-
118124
client.index('movies').reset_ranking_rules
@@ -246,9 +252,10 @@ settings_guide_ranking_rules_1: |-
246252
'typo',
247253
'proximity',
248254
'attribute',
255+
'sort',
249256
'exactness',
250-
'asc(release_date)',
251-
'desc(rank)'
257+
'release_date:asc',
258+
'rank:desc'
252259
]
253260
})
254261
settings_guide_distinct_1: |-
@@ -348,3 +355,29 @@ get_dump_status_1: |-
348355
client.get_dump_status(20201006-053243949)
349356
phrase_search_1: |-
350357
client.index('movies').search('"african american" horror')
358+
sorting_guide_update_sortable_attributes_1: |-
359+
client.index('books').update_sortable_attributes(['author', 'price'])
360+
sorting_guide_update_ranking_rules_1: |-
361+
client.index('books').update_ranking_rules([
362+
'words',
363+
'sort',
364+
'typo',
365+
'proximity',
366+
'attribute',
367+
'exactness'
368+
])
369+
sorting_guide_sort_parameter_1: |-
370+
client.index('books').search('science fiction', { sort: ['price:asc'] })
371+
sorting_guide_sort_parameter_2: |-
372+
client.index('books').search('butler', { sort: ['author:desc'] })
373+
get_sortable_attributes_1: |-
374+
client.index('books').sortable_attributes
375+
update_sortable_attributes_1: |-
376+
client.index('books').update_sortable_attributes([
377+
'price',
378+
'author'
379+
])
380+
reset_sortable_attributes_1: |-
381+
client.index('books').reset_sortable_attributes
382+
search_parameter_guide_sort_1: |-
383+
client.index('books').search('science fiction', { sort: ['price:asc'] })

.rubocop_todo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-06-23 16:19:20 UTC using RuboCop version 1.16.1.
3+
# on 2021-09-01 13:50:39 UTC using RuboCop version 1.19.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -14,16 +14,16 @@ Gemspec/DateAssignment:
1414
Exclude:
1515
- 'meilisearch.gemspec'
1616

17-
# Offense count: 32
17+
# Offense count: 33
1818
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
1919
# IgnoredMethods: refine
2020
Metrics/BlockLength:
21-
Max: 460
21+
Max: 497
2222

2323
# Offense count: 1
2424
# Configuration parameters: CountComments, CountAsOne.
2525
Metrics/ClassLength:
26-
Max: 215
26+
Max: 226
2727

2828
# Offense count: 1
2929
Naming/AccessorMethodName:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ JSON output:
151151

152152
## 🤖 Compatibility with MeiliSearch
153153

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

156156
## 💡 Learn More
157157

lib/meilisearch/index.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,21 @@ def update_filterable_attributes(filterable_attributes)
296296
def reset_filterable_attributes
297297
http_delete "/indexes/#{@uid}/settings/filterable-attributes"
298298
end
299+
300+
### SETTINGS - SORTABLE ATTRIBUTES
301+
302+
def sortable_attributes
303+
http_get "/indexes/#{@uid}/settings/sortable-attributes"
304+
end
305+
alias get_sortable_attributes sortable_attributes
306+
307+
def update_sortable_attributes(sortable_attributes)
308+
http_post "/indexes/#{@uid}/settings/sortable-attributes", sortable_attributes
309+
end
310+
alias sortable_attributes= update_sortable_attributes
311+
312+
def reset_sortable_attributes
313+
http_delete "/indexes/#{@uid}/settings/sortable-attributes"
314+
end
299315
end
300316
end

spec/meilisearch/index/search/offset_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
end
3636

3737
it 'does a placeholder search with an offset set to 3 and custom ranking rules' do
38-
response = @index.update_ranking_rules(['asc(objectId)'])
38+
response = @index.update_ranking_rules(['objectId:asc'])
3939
@index.wait_for_pending_update(response['updateId'])
4040
response = @index.search('')
4141
response_with_offset = @index.search('', offset: 3)

spec/meilisearch/index/search/q_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@
4747

4848
it 'does a basic search with an empty query and a custom ranking rule' do
4949
response = @index.update_ranking_rules([
50-
'typo',
5150
'words',
51+
'typo',
52+
'sort',
5253
'proximity',
5354
'attribute',
5455
'exactness',
55-
'asc(objectId)'
56+
'objectId:asc'
5657
])
5758
@index.wait_for_pending_update(response['updateId'])
5859
response = @index.search('')
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe 'MeiliSearch::Index - Sorted search' do
4+
before(:all) do
5+
@documents = [
6+
{
7+
objectId: 123,
8+
title: 'Pride and Prejudice',
9+
year: 1813,
10+
author: 'Jane Austen',
11+
genre: 'romance'
12+
},
13+
{
14+
objectId: 456,
15+
title: 'Le Petit Prince',
16+
year: 1943,
17+
author: 'Antoine de Saint-Exupéry',
18+
genre: 'adventure'
19+
},
20+
{
21+
objectId: 1,
22+
title: 'Alice In Wonderland',
23+
year: 1865,
24+
author: 'Lewis Carroll',
25+
genre: 'adventure'
26+
},
27+
{
28+
objectId: 2,
29+
title: 'Le Rouge et le Noir',
30+
year: 1830,
31+
author: 'Stendhal',
32+
genre: 'romance'
33+
},
34+
{
35+
objectId: 1344,
36+
title: 'The Hobbit',
37+
year: 1937,
38+
author: 'J. R. R. Tolkien',
39+
genre: 'adventure'
40+
},
41+
{
42+
objectId: 4,
43+
title: 'Harry Potter and the Half-Blood Prince',
44+
year: 2005,
45+
author: 'J. K. Rowling',
46+
genre: 'fantasy'
47+
},
48+
{
49+
objectId: 2056,
50+
title: 'Harry Potter and the Deathly Hallows',
51+
year: 2007,
52+
author: 'J. K. Rowling',
53+
genre: 'fantasy'
54+
},
55+
{
56+
objectId: 42,
57+
title: 'The Hitchhiker\'s Guide to the Galaxy',
58+
year: 1978,
59+
author: 'Douglas Adams'
60+
},
61+
{
62+
objectId: 190,
63+
title: 'A Game of Thrones',
64+
year: 1996,
65+
author: 'George R. R. Martin',
66+
genre: 'fantasy'
67+
}
68+
]
69+
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
70+
clear_all_indexes(client)
71+
@index = client.create_index('books')
72+
response = @index.add_documents(@documents)
73+
@index.wait_for_pending_update(response['updateId'])
74+
response = @index.update_sortable_attributes(['year', 'author'])
75+
@index.wait_for_pending_update(response['updateId'])
76+
response = @index.update_ranking_rules([
77+
'sort',
78+
'words',
79+
'typo',
80+
'proximity',
81+
'attribute',
82+
'exactness'
83+
])
84+
@index.wait_for_pending_update(response['updateId'])
85+
end
86+
87+
after(:all) do
88+
@index.delete
89+
end
90+
91+
it 'does a custom search with one sort' do
92+
response = @index.search('prince', { sort: ['year:desc'] })
93+
expect(response['hits'].count).to eq(2)
94+
expect(response['hits'].first['objectId']).to eq(4)
95+
end
96+
97+
it 'does a custom search by sorting on strings' do
98+
response = @index.search('prince', { sort: ['author:asc'] })
99+
expect(response['hits'].count).to eq(2)
100+
expect(response['hits'].first['objectId']).to eq(456)
101+
end
102+
103+
it 'does a custom search with multiple sort' do
104+
response = @index.search('pr', { sort: ['year:desc', 'author:asc'] })
105+
expect(response['hits'].count).to eq(3)
106+
expect(response['hits'].first['objectId']).to eq(4)
107+
end
108+
109+
it 'does a placeholder search with multiple sort' do
110+
response = @index.search('', { sort: ['year:desc', 'author:asc'] })
111+
expect(response['hits'].count).to eq(@documents.count)
112+
expect(response['hits'].first['objectId']).to eq(2056)
113+
end
114+
end

0 commit comments

Comments
 (0)