index
About this widget
index
is the component that lets you apply widgets to a dedicated index. It’s useful if you want to build an interface that targets multiple indices.
This pattern is also called “Federated Search”, more information can be found in the guides dedicated to it.
The position of index
in the widgets tree impacts which search parameters are applied. Search parameters created by widgets are forwarded to their child index
widgets.
1
2
3
4
5
6
7
8
9
search.addWidgets([
instantsearch.widgets.searchBox(),
instantsearch.widgets.hits(),
instantsearch.widgets.index({ indexName: 'instant_search' }).addWidgets([
// The index inherits from the parent's `searchBox` search parameters
instantsearch.widgets.hits(),
]),
]);
The only exception to this rule is when two widgets own the same part of your UI state like two searchBox
es, or two refinementList
s on the same attribute. In that case, the latter takes precedence over the first and overrides the search parameters.
1
2
3
4
5
6
7
8
9
10
search.addWidgets([
instantsearch.widgets.searchBox(),
instantsearch.widgets.hits(),
instantsearch.widgets.index({ indexName: 'instant_search' }).addWidgets([
// The index does not inherit from the parent's `searchBox` search parameters
instantsearch.widgets.searchBox(),
instantsearch.widgets.hits(),
]),
]);
The same rule applies when you nest multiple index
widgets.
Examples
1
2
3
4
5
6
instantsearch.widgets
.index({ indexName: 'instant_search' })
.addWidgets([
// Add widgets
// ...
]);
Options
indexName
|
type: string
Required
The index to search into. |
||
Copy
|
|||
indexId
|
type: string
default: value provided for indexName
Optional
An identifier for the |
||
Copy
|
Methods
addWidgets
|
Adds widget(s) to the index. |
||
Copy
|
|||
removeWidgets
|
Removes widget(s) from the |
||
Copy
|