Skip to content

Commit ee3715f

Browse files
committed
Update README with new multi search feature
Federated search can follow right after multi search when it is added.
1 parent e1d210e commit ee3715f

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

README.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,7 @@ multi_search_results = MeiliSearch::Rails.multi_search(
241241
)
242242
```
243243

244-
You can iterate through the results with `.each` or `.each_result`:
245-
246-
```erb
247-
<% multi_search_results.each do |record| %>
248-
<p><%= record.title %></p>
249-
<p><%= record.author %></p>
250-
<% end %>
251-
252-
<p>Harry Potter and the Philosopher's Stone</p>
253-
<p>J. K. Rowling</p>
254-
<p>Harry Potter and the Chamber of Secrets</p>
255-
<p>J. K. Rowling</p>
256-
<p>Attack on Titan</p>
257-
<p>Iseyama</p>
258-
```
259-
244+
Use `#each_result` to loop through pairs of your provided keys and the results:
260245
```erb
261246
<% multi_search_results.each_result do |klass, results| %>
262247
<p><%= klass.name.pluralize %></p>
@@ -280,6 +265,55 @@ You can iterate through the results with `.each` or `.each_result`:
280265
</ul>
281266
```
282267

268+
Records are loaded when the keys are models, or when `:class_name` option is passed:
269+
270+
```ruby
271+
multi_search_results = MeiliSearch::Rails.multi_search(
272+
'books' => { q: 'Harry', class_name: 'Book' },
273+
'mangas' => { q: 'Attack', class_name: 'Manga' }
274+
)
275+
```
276+
277+
Otherwise, hashes are returned.
278+
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:
280+
281+
```ruby
282+
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' }
285+
)
286+
```
287+
288+
You can search the same index multiple times by specifying `:index_name`:
289+
290+
```ruby
291+
query = 'hero'
292+
multi_search_results = MeiliSearch::Rails.multi_search(
293+
'Isekai Manga' => { q: query, class_name: 'Manga', filters: 'genre:isekai', index_name: 'mangas_production' }
294+
'Shounen Manga' => { q: query, class_name: 'Manga', filters: 'genre:shounen', index_name: 'mangas_production' }
295+
'Steampunk Manga' => { q: query, class_name: 'Manga', filters: 'genre:steampunk', index_name: 'mangas_production' }
296+
)
297+
```
298+
299+
**DEPRECATED:** You used to be able to iterate through a flattened collection with `.each`:
300+
301+
```erb
302+
<% multi_search_results.each do |record| %>
303+
<p><%= record.title %></p>
304+
<p><%= record.author %></p>
305+
<% end %>
306+
307+
<p>Harry Potter and the Philosopher's Stone</p>
308+
<p>J. K. Rowling</p>
309+
<p>Harry Potter and the Chamber of Secrets</p>
310+
<p>J. K. Rowling</p>
311+
<p>Attack on Titan</p>
312+
<p>Iseyama</p>
313+
```
314+
315+
But this has been deprecated in favor of **federated search**.
316+
283317
See the [official multi search documentation](https://www.meilisearch.com/docs/reference/api/multi_search).
284318

285319
## 🪛 Options

0 commit comments

Comments
 (0)