Skip to content

Commit c27fac2

Browse files
bors[bot]meili-botcurquiza
authored
Merge #92
92: Changes related to the next MeiliSearch release (v0.25.0) r=brunoocasali a=meili-bot This PR gathers the changes related to the next MeiliSearch release (v0.25.0) so that this package is ready when the official release is out. ⚠️ This PR should NOT be merged until: - the next release of MeiliSearch (v0.25.0) is out. - the [`meilisearch-ruby`](https://github.com/meilisearch/meilisearch-ruby) dependency has been released to be compatible with MeiliSearch v0.25.0. Once the release is out, the `meilisearch-ruby` version in this package should be upgraded and committed to this branch. _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 - curqui <[email protected]>
2 parents 5f177c6 + b75a5c9 commit c27fac2

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source 'http://rubygems.org'
22

33
gem 'json', '~> 2.5', '>= 2.5.1'
4-
gem 'meilisearch', '~> 0.17.0'
4+
gem 'meilisearch', '~> 0.18.0'
55

66
gem 'rubysl', '~> 2.0', platform: :rbx if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
77

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ To learn more about MeiliSearch, check out our [Documentation](https://docs.meil
5858

5959
## 🤖 Compatibility with MeiliSearch
6060

61-
This package only guarantees the compatibility with the [version v0.24.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.24.0).
61+
This package only guarantees the compatibility with the [version v0.25.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.25.0).
6262

6363
## 🔧 Installation <!-- omit in toc -->
6464

@@ -659,7 +659,7 @@ class Book < ActiveRecord::Base
659659
end
660660
end
661661
```
662-
🚨 This is only recommended for testing purposes, the gem will call the `wait_for_pending_update` method that will stop your code execution until the asynchronous task has been processed by MeilSearch.
662+
🚨 This is only recommended for testing purposes, the gem will call the `wait_for_task` method that will stop your code execution until the asynchronous task has been processed by MeilSearch.
663663

664664
##### Disable auto-indexing & auto-removal <!-- omit in toc -->
665665

lib/meilisearch-rails.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ class SafeIndex
237237
def initialize(index_uid, raise_on_failure, options)
238238
client = MeiliSearch.client
239239
primary_key = options[:primary_key] || MeiliSearch::IndexSettings::DEFAULT_PRIMARY_KEY
240-
@index = client.get_or_create_index(index_uid, { primaryKey: primary_key })
240+
client.create_index(index_uid, { primaryKey: primary_key })
241+
@index = client.index(index_uid)
241242
@raise_on_failure = raise_on_failure.nil? || raise_on_failure
242243
end
243244

@@ -254,12 +255,12 @@ def initialize(index_uid, raise_on_failure, options)
254255
end
255256
end
256257

257-
# special handling of wait_for_pending_update to handle null task_id
258-
def wait_for_pending_update(update_id)
259-
return if update_id.nil? && !@raise_on_failure # ok
258+
# special handling of wait_for_task to handle null task_id
259+
def wait_for_task(task_uid)
260+
return if task_uid.nil? && !@raise_on_failure # ok
260261

261-
SafeIndex.log_or_throw(:wait_for_pending_update, @raise_on_failure) do
262-
@index.wait_for_pending_update(update_id)
262+
SafeIndex.log_or_throw(:wait_for_task, @raise_on_failure) do
263+
@index.wait_for_task(task_uid)
263264
end
264265
end
265266

@@ -442,7 +443,7 @@ def ms_reindex!(batch_size = MeiliSearch::IndexSettings::DEFAULT_BATCH_SIZE, syn
442443
next if ms_indexing_disabled?(options)
443444

444445
index = ms_ensure_init(options, settings)
445-
last_update = nil
446+
last_task = nil
446447

447448
ms_find_in_batches(batch_size) do |group|
448449
if ms_conditional_index?(options)
@@ -457,9 +458,9 @@ def ms_reindex!(batch_size = MeiliSearch::IndexSettings::DEFAULT_BATCH_SIZE, syn
457458
attributes = attributes.to_hash unless attributes.instance_of?(Hash)
458459
attributes.merge ms_pk(options) => ms_primary_key_of(d, options)
459460
end
460-
last_update= index.add_documents(documents)
461+
last_task = index.add_documents(documents)
461462
end
462-
index.wait_for_pending_update(last_update['updateId']) if last_update && (synchronous || options[:synchronous])
463+
index.wait_for_task(last_task['uid']) if last_task && (synchronous || options[:synchronous])
463464
end
464465
nil
465466
end
@@ -474,8 +475,8 @@ def ms_set_settings(synchronous = false)
474475
end
475476

476477
index = SafeIndex.new(ms_index_uid(options), true, options)
477-
update = index.update_settings(final_settings)
478-
index.wait_for_pending_update(update['updateId']) if synchronous
478+
task = index.update_settings(final_settings)
479+
index.wait_for_task(task['uid']) if synchronous
479480
end
480481
end
481482

@@ -484,8 +485,8 @@ def ms_index_documents(documents, synchronous = false)
484485
next if ms_indexing_disabled?(options)
485486

486487
index = ms_ensure_init(options, settings)
487-
update = index.add_documents(documents.map { |d| settings.get_attributes(d).merge ms_pk(options) => ms_primary_key_of(d, options) })
488-
index.wait_for_pending_update(update['updateId']) if synchronous || options[:synchronous]
488+
task = index.add_documents(documents.map { |d| settings.get_attributes(d).merge ms_pk(options) => ms_primary_key_of(d, options) })
489+
index.wait_for_task(task['uid']) if synchronous || options[:synchronous]
489490
end
490491
end
491492

spec/integration_spec.rb

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,12 @@ class SerializedDocument < ActiveRecord::Base
12481248
end
12491249

12501250
describe 'People' do
1251+
it 'adds custom complex attribute' do
1252+
People.create(first_name: 'Jane', last_name: 'Doe', card_number: 75_801_887)
1253+
result = People.raw_search('Jane')
1254+
expect(result['hits'][0]['full_name']).to eq('Jane Doe')
1255+
end
1256+
12511257
it 'has as uid the custom name specified' do
12521258
expect(People.index.uid).to eq(safe_index_uid('MyCustomPeople'))
12531259
end
@@ -1257,26 +1263,12 @@ class SerializedDocument < ActiveRecord::Base
12571263
expect(index.primary_key).to eq('card_number')
12581264
end
12591265

1260-
it 'adds custom complex attribute' do
1261-
People.create(first_name: 'Jane', last_name: 'Doe', card_number: 75_801_887)
1262-
result = People.raw_search('Jane')
1263-
expect(result['hits'][0]['full_name']).to eq('Jane Doe')
1264-
end
1265-
12661266
it 'does not call the API if there has been no attribute change' do
1267-
person = People.search('Jane')[0]
1268-
before_save_statuses = People.index.get_all_update_status
1269-
before_save_status = before_save_statuses.last
1270-
person.first_name = 'Jane'
1271-
person.save
1272-
after_save_statuses = People.index.get_all_update_status
1273-
after_save_status = after_save_statuses.last
1274-
expect(before_save_status['updateId']).to eq(after_save_status['updateId'])
1275-
person.first_name = 'Alice'
1276-
person.save
1277-
after_change_statuses = People.index.get_all_update_status
1278-
after_change_status = after_change_statuses.last
1279-
expect(before_save_status['updateId']).not_to eq(after_change_status['updateId'])
1267+
person = People.search('Jane').first
1268+
1269+
expect do
1270+
person.update(first_name: 'Jane')
1271+
end.not_to change(People.index.tasks['results'], :size)
12801272
end
12811273

12821274
it 'does not auto-remove' do
@@ -1310,7 +1302,7 @@ class SerializedDocument < ActiveRecord::Base
13101302
Dog.create!(name: 'Toby')
13111303
Cat.create!(name: 'Felix')
13121304
index = MeiliSearch.client.index(safe_index_uid('animals'))
1313-
index.wait_for_pending_update(index.get_all_update_status.last['updateId'])
1305+
index.wait_for_task(index.tasks['results'].first['uid'])
13141306
docs = index.search('')
13151307
expect(docs['hits'].size).to eq(2)
13161308
end
@@ -1321,8 +1313,8 @@ class SerializedDocument < ActiveRecord::Base
13211313
Song.create!(name: 'Coconut nut', artist: 'Smokey Mountain', premium: false, released: true) # Only song supposed to be added to Songs index
13221314
Song.create!(name: 'Smoking hot', artist: 'Cigarettes before lunch', premium: true, released: true)
13231315
Song.create!(name: 'Floor is lava', artist: 'Volcano', premium: true, released: false)
1324-
Song.index.wait_for_pending_update(Song.index.get_all_update_status.last['updateId'])
1325-
MeiliSearch.client.index(safe_index_uid('PrivateSongs')).wait_for_pending_update(MeiliSearch.client.index(safe_index_uid('PrivateSongs')).get_all_update_status.last['updateId'])
1316+
Song.index.wait_for_task(Song.index.tasks['results'].first['uid'])
1317+
MeiliSearch.client.index(safe_index_uid('PrivateSongs')).wait_for_task(MeiliSearch.client.index(safe_index_uid('PrivateSongs')).tasks['results'].first['uid'])
13261318
results = Song.search('', index: safe_index_uid('Songs'))
13271319
expect(results.size).to eq(1)
13281320
raw_results = Song.raw_search('', index: safe_index_uid('Songs'))

0 commit comments

Comments
 (0)