Skip to content

Commit 049c571

Browse files
Merge #403
403: Rename index_name option to index_uid in multi_search r=ellnix a=ellnix Made a mistake when supporting this option, at least it has not made it to release yet. Co-authored-by: ellnix <[email protected]>
2 parents df15847 + f20a8d9 commit 049c571

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,25 @@ multi_search_results = MeiliSearch::Rails.multi_search(
276276

277277
Otherwise, hashes are returned.
278278

279-
The index to search is inferred from the model if the key is a model, if the key is a string the key is assumed to be the index unless the `:index_name` option is passed:
279+
The index to search is inferred from the model if the key is a model, if the key is a string the key is assumed to be the index unless the `:index_uid` option is passed:
280280

281281
```ruby
282282
multi_search_results = MeiliSearch::Rails.multi_search(
283-
'western' => { q: 'Harry', class_name: 'Book', index_name: 'books_production' },
284-
'japanese' => { q: 'Attack', class_name: 'Manga', index_name: 'mangas_production' }
283+
'western' => { q: 'Harry', class_name: 'Book', index_uid: 'books_production' },
284+
'japanese' => { q: 'Attack', class_name: 'Manga', index_uid: 'mangas_production' }
285285
)
286286
```
287287

288288
### Multi search the same index <!-- omit in toc -->
289289

290-
You can search the same index multiple times by specifying `:index_name`:
290+
You can search the same index multiple times by specifying `:index_uid`:
291291

292292
```ruby
293293
query = 'hero'
294294
multi_search_results = MeiliSearch::Rails.multi_search(
295-
'Isekai Manga' => { q: query, class_name: 'Manga', filters: 'genre:isekai', index_name: 'mangas_production' }
296-
'Shounen Manga' => { q: query, class_name: 'Manga', filters: 'genre:shounen', index_name: 'mangas_production' }
297-
'Steampunk Manga' => { q: query, class_name: 'Manga', filters: 'genre:steampunk', index_name: 'mangas_production' }
295+
'Isekai Manga' => { q: query, class_name: 'Manga', filters: 'genre:isekai', index_uid: 'mangas_production' }
296+
'Shounen Manga' => { q: query, class_name: 'Manga', filters: 'genre:shounen', index_uid: 'mangas_production' }
297+
'Steampunk Manga' => { q: query, class_name: 'Manga', filters: 'genre:steampunk', index_uid: 'mangas_production' }
298298
)
299299
```
300300

lib/meilisearch/rails/multi_search.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Rails
55
class << self
66
def multi_search(searches)
77
search_parameters = searches.map do |(index_target, options)|
8-
index_target = options.delete(:index_name) || index_target
8+
index_target = options.delete(:index_uid) || index_target
99

1010
paginate(options) if pagination_enabled?
1111
normalize(options, index_target)

spec/multi_search_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def reset_indexes
4747
end
4848

4949
context 'with arbitrary keys' do
50-
context 'when index_name is not present' do
50+
context 'when index_uid is not present' do
5151
it 'assumes key is index and errors' do
5252
expect do
5353
MeiliSearch::Rails.multi_search(
@@ -57,12 +57,12 @@ def reset_indexes
5757
end
5858
end
5959

60-
context 'when :index_name is present' do
60+
context 'when :index_uid is present' do
6161
it 'searches the correct index' do
6262
results = MeiliSearch::Rails.multi_search(
63-
'books' => { q: 'Steve', index_name: Book.index.uid },
64-
'products' => { q: 'palm', index_name: Product.index.uid, limit: 1 },
65-
'colors' => { q: 'bl', index_name: Color.index.uid }
63+
'books' => { q: 'Steve', index_uid: Book.index.uid },
64+
'products' => { q: 'palm', index_uid: Product.index.uid, limit: 1 },
65+
'colors' => { q: 'bl', index_uid: Color.index.uid }
6666
)
6767

6868
expect(results).to contain_exactly(
@@ -74,12 +74,12 @@ def reset_indexes
7474
end
7575

7676
it 'allows searching the same index n times' do
77-
index_name = Color.index.uid
77+
index_uid = Color.index.uid
7878

7979
results = MeiliSearch::Rails.multi_search(
80-
'dark_colors' => { q: 'black', index_name: index_name },
81-
'bright_colors' => { q: 'blue', index_name: index_name },
82-
'nature_colors' => { q: 'green', index_name: index_name }
80+
'dark_colors' => { q: 'black', index_uid: index_uid },
81+
'bright_colors' => { q: 'blue', index_uid: index_uid },
82+
'nature_colors' => { q: 'green', index_uid: index_uid }
8383
)
8484

8585
expect(results).to contain_exactly(
@@ -92,9 +92,9 @@ def reset_indexes
9292
context 'when :class_name is also present' do
9393
it 'loads results from the correct models' do
9494
results = MeiliSearch::Rails.multi_search(
95-
'books' => { q: 'Steve', index_name: Book.index.uid, class_name: 'Book' },
96-
'products' => { q: 'palm', limit: 1, index_name: Product.index.uid, class_name: 'Product' },
97-
'colors' => { q: 'bl', index_name: Color.index.uid, class_name: 'Color' }
95+
'books' => { q: 'Steve', index_uid: Book.index.uid, class_name: 'Book' },
96+
'products' => { q: 'palm', limit: 1, index_uid: Product.index.uid, class_name: 'Product' },
97+
'colors' => { q: 'bl', index_uid: Color.index.uid, class_name: 'Color' }
9898
)
9999

100100
expect(results).to contain_exactly(

0 commit comments

Comments
 (0)