@@ -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,59 @@ 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+ ### Multi search the same index <!-- omit in toc -->
289+
290+ You can search the same index multiple times by specifying ` :index_name ` :
291+
292+ ``` ruby
293+ query = ' hero'
294+ 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' }
298+ )
299+ ```
300+
301+ ### Deprecated #each <!-- omit in toc -->
302+
303+ ** DEPRECATED:** You used to be able to iterate through a flattened collection with ` .each ` :
304+
305+ ``` erb
306+ <% multi_search_results.each do |record| %>
307+ <p><%= record.title %></p>
308+ <p><%= record.author %></p>
309+ <% end %>
310+
311+ <p>Harry Potter and the Philosopher's Stone</p>
312+ <p>J. K. Rowling</p>
313+ <p>Harry Potter and the Chamber of Secrets</p>
314+ <p>J. K. Rowling</p>
315+ <p>Attack on Titan</p>
316+ <p>Iseyama</p>
317+ ```
318+
319+ But this has been deprecated in favor of ** federated search** .
320+
283321See the [ official multi search documentation] ( https://www.meilisearch.com/docs/reference/api/multi_search ) .
284322
285323## 🪛 Options
0 commit comments