Multi-index search (federated search) is a method for searching multiple data sources simultaneously.
This means that when users enter a search term, Algolia will look for and display results from all these data sources.This doesn’t necessarily mean that the results from Algolia indices are combined since their contents could be quite different.
Your approach may be to display the results from each separately.
You could display the top-rated items from a movie index alongside the list of results from a book index.
Or you could display category matches alongside the list of results from a product index
The following example uses a single search view to search in two indices. This is achieved through the aggregation of two HitsSearchers by the MultiSearcher.
Each of them targets a specific index: the first one is mobile_demo_actors and the second is mobile_demo_movies. The results are presented in the dedicated sections of a LazyColumn.The source code of this example is on GitHub.
import com.algolia.instantsearch.core.Indexable@Serializabledata class Movie( val title: String, override val objectID: String, override val _highlightResult: JsonObject?) : Indexable, Highlightable { val highlightedTitle get() = getHighlight("title")}@Serializabledata class Actor( val name: String, override val objectID: String, override val _highlightResult: JsonObject?) : Indexable, Highlightable { val highlightedName get() = getHighlight("name")}
This example uses a single search view to search in the index and values for attributes of the same index.
This is achieved through the aggregation of the HitsSearcher and the FacetSearcher by the MultiSearcher.
The results are presented in the dedicated sections of a LazyColumn.The source code of this example is on GitHub.
import com.algolia.instantsearch.core.Indexable@Serializabledata class Product( val name: String, val description: String, val image: String, override val objectID: String, override val _highlightResult: JsonObject?) : Indexable, Highlightable { val highlightedName get() = getHighlight("name") val highlightedDescription get() = getHighlight("description")}
Algolia can help you display both category matches and results if you:
Add categories to your Query Suggestions either inline or listed below a result. For example, you might see the following in your Query Suggestions list “game of thrones in Books”
Use multi-index search to display categories from a separate category index. This is useful if you want to display categories and Query Suggestions at the same time. Clicking such a result typically redirects to a category page. The following is a sample dataset for a product index and a category index.
[ { "name": "Court shoes", "category": "Fashion > Women > Shoes > Court shoes", "description": "A dress shoe with a low-cut front and a closed heel.", "url": "/women/shoes/court/" }, { "name": "Dress shirt", "category": "Fashion > Men > Shirts > Dress shirt", "description": "A long-sleeved, button-up formal shirt that is typically worn with a suit or tie.", "url": "/men/shirts/dress/" }]