Skip to content

Commit add6a7e

Browse files
authored
Bump MeiliSearch to v0.13.0 (#74)
* Update README.md * Remove sysinfo routes (#75) * Remove sysinfo routes * Remove sys info in code samples * Update settings following the settings behavior changes on MeiliSearch (#78) * Update settings following the settings behavior changes on MeiliSearch * Remove acceptNewFields examples in code samples * Use POST instead of GET in search method (#77) Add tests for placeholder
1 parent 9e54aab commit add6a7e

File tree

11 files changed

+65
-137
lines changed

11 files changed

+65
-137
lines changed

.code-samples.meilisearch.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,11 @@ reset_searchable_attributes_1: |-
4343
get_displayed_attributes_1: |-
4444
update_displayed_attributes_1: |-
4545
reset_displayed_attributes_1: |-
46-
get_accept_new_fields_1: |-
47-
update_accept_new_fields_1: |-
4846
get_index_stats_1: |-
4947
get_indexes_stats_1: |-
5048
get_health_1: |-
5149
update_health_1: |-
5250
get_version_1: |-
53-
get_pretty_sys_info_1: |-
54-
get_sys_info_1: |-
5551
distinct_attribute_guide_1: |-
5652
field_properties_guide_searchable_1: |-
5753
field_properties_guide_displayed_1: |-
@@ -74,7 +70,6 @@ settings_guide_ranking_rules_1: |-
7470
settings_guide_distinct_1: |-
7571
settings_guide_searchable_1: |-
7672
settings_guide_displayed_1: |-
77-
settings_guide_accept_new_fields_1: |-
7873
add_movies_json_1: |-
7974
documents_guide_add_movie_1: |-
8075
search_guide_1: |-

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ Output:
109109
## 🤖 Compatibility with MeiliSearch
110110

111111
This package is compatible with the following MeiliSearch versions:
112-
- `v0.12.X`
113-
- `v0.11.X`
112+
- `v0.13.X`
114113

115114
## 🎬 Examples
116115

lib/meilisearch/client.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ def version
7373
http_get '/version'
7474
end
7575

76-
def sysinfo
77-
http_get '/sys-info'
78-
end
79-
80-
def pretty_sysinfo
81-
http_get '/sys-info/pretty'
82-
end
83-
8476
def stats
8577
http_get '/stats'
8678
end

lib/meilisearch/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize(http_code, http_message, http_body)
2121
@http_message = http_message
2222
@ms_message ||= 'MeiliSearch API has not returned any error message'
2323
@ms_link ||= '<no documentation link found>'
24-
@message = "#{http_code} #{http_message} - #{@ms_message.capitalize}. See #{ms_link}."
24+
@message = "#{http_code} #{http_message} - #{@ms_message}. See #{ms_link}."
2525
super(details)
2626
end
2727

lib/meilisearch/index.rb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,8 @@ def delete_all_documents
8181
### SEARCH
8282

8383
def search(query, options = {})
84-
parsed_options = options.transform_keys(&:to_sym).map do |k, v|
85-
if [:facetFilters, :facetsDistribution].include?(k)
86-
[k, v.inspect]
87-
elsif v.is_a?(Array)
88-
[k, v.join(',')]
89-
else
90-
[k, v]
91-
end
92-
end.to_h
93-
http_get "/indexes/#{@uid}/search", { q: query }.merge(parsed_options)
84+
parsed_options = options.compact
85+
http_post "/indexes/#{@uid}/search", { q: query }.merge(parsed_options)
9486
end
9587

9688
### UPDATES
@@ -244,17 +236,6 @@ def reset_displayed_attributes
244236
http_delete "/indexes/#{@uid}/settings/displayed-attributes"
245237
end
246238

247-
### SETTINGS - ACCEPT NEW FIELS VALUE
248-
249-
def accept_new_fields
250-
http_get "/indexes/#{@uid}/settings/accept-new-fields"
251-
end
252-
alias get_accept_new_fields accept_new_fields
253-
254-
def update_accept_new_fields(accept_new_fields)
255-
http_post "/indexes/#{@uid}/settings/accept-new-fields", accept_new_fields
256-
end
257-
258239
### SETTINGS - ATTRIBUTES FOR FACETING
259240

260241
def attributes_for_faceting

spec/meilisearch/client/stats_spec.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@
1313
expect(response).to have_key('pkgVersion')
1414
end
1515

16-
it 'gets sys-info' do
17-
response = @client.sysinfo
18-
expect(response).to be_a(Hash)
19-
expect(response).to have_key('memoryUsage')
20-
expect(response).to have_key('processorUsage')
21-
expect(response).to have_key('global')
22-
expect(response['global']['totalMemory']).not_to be_a(String)
23-
expect(response['processorUsage'].first).not_to be_a(String)
24-
end
25-
26-
it 'gets pretty sys-info' do
27-
response = @client.pretty_sysinfo
28-
expect(response).to be_a(Hash)
29-
expect(response).to have_key('memoryUsage')
30-
expect(response).to have_key('processorUsage')
31-
expect(response).to have_key('global')
32-
expect(response['global']['totalMemory']).to be_a(String)
33-
expect(response['global']['totalMemory']).to end_with('B')
34-
expect(response['processorUsage'].first).to be_a(String)
35-
expect(response['processorUsage'].first).to end_with('%')
36-
end
37-
3816
it 'gets stats' do
3917
response = @client.stats
4018
expect(response).to have_key('databaseSize')

spec/meilisearch/index/base_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
new_primary_key = 'id_test'
4545
expect do
4646
@index2.update(primaryKey: new_primary_key)
47-
end.to raise_bad_request_meilisearch_api_error
48-
# temporary, will be raise a 'primary_key_already_present' code in the next MS release
47+
end.to raise_meilisearch_api_error_with(
48+
400,
49+
'primary_key_already_present',
50+
'invalid_request_error'
51+
)
4952
end
5053

5154
it 'deletes index' do

spec/meilisearch/index/documents_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@
349349
it 'returns a 400' do
350350
expect do
351351
index.add_documents(documents)
352-
end.to raise_bad_request_meilisearch_api_error
353-
# temporary, will be return a 'missing_primary_key' code in the next MS release
352+
end.to raise_missing_primary_key_meilisearch_api_error
354353
end
355354
end
356355

spec/meilisearch/index/search_spec.rb

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'MeiliSearch::Index - Search' do
44
before(:all) do
5-
documents = [
5+
@documents = [
66
{ objectId: 123, title: 'Pride and Prejudice', genre: 'romance' },
77
{ objectId: 456, title: 'Le Petit Prince', genre: 'adventure' },
88
{ objectId: 1, title: 'Alice In Wonderland', genre: 'adventure' },
@@ -14,7 +14,7 @@
1414
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
1515
clear_all_indexes(client)
1616
@index = client.create_index('books')
17-
@index.add_documents(documents)
17+
@index.add_documents(@documents)
1818
sleep(0.1)
1919
end
2020

@@ -42,6 +42,21 @@
4242
expect(response['hits'].first).not_to have_key('_formatted')
4343
end
4444

45+
it 'does a basic search with an empty query' do
46+
response = @index.search('')
47+
expect(response).to be_a(Hash)
48+
expect(response.keys).to contain_exactly(*default_search_response_keys)
49+
expect(response['hits'].count).to eq(0)
50+
end
51+
52+
it 'does a basic search with an nil query' do
53+
response = @index.search(nil)
54+
expect(response).to be_a(Hash)
55+
expect(response.keys).to contain_exactly(*default_search_response_keys)
56+
expect(response['hits'].count).to eq(@documents.count)
57+
expect(response['hits'].first).not_to have_key('_formatted')
58+
end
59+
4560
it 'does a custom search with limit' do
4661
response = @index.search('the', limit: 1)
4762
expect(response).to be_a(Hash)
@@ -51,15 +66,30 @@
5166
end
5267

5368
it 'does a custom search with highlight' do
54-
response = @index.search('the', attributesToHighlight: '*')
69+
response = @index.search('the', attributesToHighlight: ['*'])
5570
expect(response).to be_a(Hash)
5671
expect(response.keys).to contain_exactly(*default_search_response_keys)
5772
expect(response['hits'].count).to eq(3)
5873
expect(response['hits'].first).to have_key('_formatted')
5974
end
6075

76+
it 'does a custom search with an empty query' do
77+
response = @index.search('', attributesToHighlight: ['*'])
78+
expect(response).to be_a(Hash)
79+
expect(response.keys).to contain_exactly(*default_search_response_keys)
80+
expect(response['hits'].count).to eq(0)
81+
end
82+
83+
it 'does a custom search with an nil query' do
84+
response = @index.search(nil, attributesToHighlight: ['*'])
85+
expect(response).to be_a(Hash)
86+
expect(response.keys).to contain_exactly(*default_search_response_keys)
87+
expect(response['hits'].count).to eq(@documents.count)
88+
expect(response['hits'].first).to have_key('_formatted')
89+
end
90+
6191
it 'does a custom search with attributesToRetrieve as string' do
62-
response = @index.search('the', attributesToRetrieve: 'title')
92+
response = @index.search('the', attributesToRetrieve: ['title'])
6393
expect(response).to be_a(Hash)
6494
expect(response.keys).to contain_exactly(*default_search_response_keys)
6595
expect(response['hits'].count).to eq(3)

spec/meilisearch/index/settings_spec.rb

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
'exactness'
1717
]
1818
end
19+
let(:default_searchable_attributes) { ['*'] }
20+
let(:default_displayed_attributes) { ['*'] }
1921

2022
let(:settings_keys) do
2123
[
@@ -25,7 +27,6 @@
2527
'displayedAttributes',
2628
'stopWords',
2729
'synonyms',
28-
'acceptNewFields',
2930
'attributesForFaceting'
3031
]
3132
end
@@ -46,11 +47,10 @@
4647
expect(response.keys).to contain_exactly(*settings_keys)
4748
expect(response['rankingRules']).to eq(default_ranking_rules)
4849
expect(response['distinctAttribute']).to be_nil
49-
expect(response['searchableAttributes']).to eq([])
50-
expect(response['displayedAttributes']).to eq([])
50+
expect(response['searchableAttributes']).to eq(default_searchable_attributes)
51+
expect(response['displayedAttributes']).to eq(default_displayed_attributes)
5152
expect(response['stopWords']).to eq([])
5253
expect(response['synonyms']).to eq({})
53-
expect(response['acceptNewFields']).to be_truthy
5454
end
5555

5656
it 'updates multiples settings at the same time' do
@@ -171,8 +171,7 @@
171171

172172
it 'gets default values of searchable attributes' do
173173
response = index.searchable_attributes
174-
expect(response).to be_a(Array)
175-
expect(response).to be_empty
174+
expect(response).to eq(default_searchable_attributes)
176175
end
177176

178177
it 'updates searchable attributes' do
@@ -187,6 +186,7 @@
187186
expect(response).to have_key('updateId')
188187
sleep(0.1)
189188
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
189+
expect(index.searchable_attributes).to eq(default_searchable_attributes)
190190
end
191191
end
192192

@@ -203,8 +203,7 @@
203203

204204
it 'gets default values of displayed attributes' do
205205
response = index.displayed_attributes
206-
expect(response).to be_a(Array)
207-
expect(response).to be_empty
206+
expect(response).to eq(default_displayed_attributes)
208207
end
209208

210209
it 'updates displayed attributes' do
@@ -219,62 +218,7 @@
219218
expect(response).to have_key('updateId')
220219
sleep(0.1)
221220
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
222-
end
223-
end
224-
225-
context 'On accept-new-fields sub-routes' do
226-
before(:all) do
227-
@uid = SecureRandom.hex(4)
228-
@client.create_index(@uid)
229-
end
230-
231-
after(:all) { clear_all_indexes(@client) }
232-
233-
let(:index) { @client.index(@uid) }
234-
235-
it 'gets default values of acceptNewFields' do
236-
expect(index.accept_new_fields).to be_truthy
237-
end
238-
239-
it 'adds searchable or display attributes when truthy' do
240-
index.update_searchable_attributes(['title', 'description'])
241-
sleep(0.1)
242-
index.update_displayed_attributes(['title', 'description'])
243-
sleep(0.1)
244-
index.add_documents(id: 1, title: 'Test', comment: 'comment test')
245-
sleep(0.1)
246-
sa = index.searchable_attributes
247-
da = index.displayed_attributes
248-
expect(sa).to contain_exactly('id', 'title', 'description', 'comment')
249-
expect(da).to contain_exactly('id', 'title', 'description', 'comment')
250-
index.update_searchable_attributes([])
251-
sleep(0.1)
252-
index.update_displayed_attributes([])
253-
sleep(0.1)
254-
index.delete_all_documents
255-
sleep(0.1)
256-
end
257-
258-
it 'updates displayed attributes' do
259-
response = index.update_accept_new_fields(false)
260-
expect(response).to have_key('updateId')
261-
sleep(0.1)
262-
expect(index.accept_new_fields).to be_falsy
263-
end
264-
265-
it 'does not add searchable or display attributes when falsy' do
266-
index.update_searchable_attributes(['title', 'description'])
267-
sleep(0.1)
268-
index.update_displayed_attributes(['title', 'description'])
269-
sleep(0.1)
270-
index.update_accept_new_fields(false)
271-
sleep(0.1)
272-
index.add_documents(id: 1, title: 'Test', comment: 'comment test', note: 'note')
273-
sleep(0.1)
274-
sa = index.searchable_attributes
275-
da = index.displayed_attributes
276-
expect(sa).to contain_exactly('title', 'description')
277-
expect(da).to contain_exactly('title', 'description')
221+
expect(index.displayed_attributes).to eq(default_displayed_attributes)
278222
end
279223
end
280224

@@ -447,11 +391,10 @@
447391
expect(response.keys).to contain_exactly(*settings_keys)
448392
expect(response['rankingRules']).to eq(default_ranking_rules)
449393
expect(response['distinctAttribute']).to be_nil
450-
expect(response['searchableAttributes']).to eq(['id'])
451-
expect(response['displayedAttributes']).to eq(['id'])
394+
expect(response['searchableAttributes']).to eq(default_searchable_attributes)
395+
expect(response['displayedAttributes']).to eq(default_displayed_attributes)
452396
expect(response['stopWords']).to eq([])
453397
expect(response['synonyms']).to eq({})
454-
expect(response['acceptNewFields']).to be_truthy
455398
end
456399

457400
it 'updates multiples settings at the same time' do
@@ -503,7 +446,7 @@
503446
it 'does not add document when there is no primary-key' do
504447
expect do
505448
index.add_documents(title: 'Test')
506-
end.to raise_bad_request_meilisearch_api_error
449+
end.to raise_missing_primary_key_meilisearch_api_error
507450
end
508451

509452
it 'adds documents when there is a primary-key' do
@@ -522,6 +465,7 @@
522465
expect(response).to have_key('updateId')
523466
sleep(0.1)
524467
expect(index.get_update_status(response['updateId'])['status']).to eq('processed')
468+
expect(index.searchable_attributes).to eq(['*'])
525469
end
526470
end
527471

@@ -541,7 +485,6 @@
541485
expect(index.method(:distinct_attribute) == index.method(:get_distinct_attribute)).to be_truthy
542486
expect(index.method(:searchable_attributes) == index.method(:get_searchable_attributes)).to be_truthy
543487
expect(index.method(:displayed_attributes) == index.method(:get_displayed_attributes)).to be_truthy
544-
expect(index.method(:accept_new_fields) == index.method(:get_accept_new_fields)).to be_truthy
545488
expect(index.method(:synonyms) == index.method(:get_synonyms)).to be_truthy
546489
expect(index.method(:stop_words) == index.method(:get_stop_words)).to be_truthy
547490
expect(index.method(:attributes_for_faceting) == index.method(:get_attributes_for_faceting)).to be_truthy

0 commit comments

Comments
 (0)