instantsearch
instantsearch({ indexName: string, searchClient: object, // Optional parameters numberLocale: string, searchFunction: function, searchParameters: object, stalledSearchDelay: number, routing: boolean|object, });
About this widget
The instantsearch
object is the main component of InstantSearch.js. It manages the widget and lets you add new ones.
Two parameters are required to get you started with InstantSearch.js:
indexName
: the main index that you need to use for your new search UIsearchClient
: the search client to plug to InstantSearch.js
The search client provided by Algolia needs an appId
and an apiKey
. Those parameters can be found in your Algolia dashboard.
To get up and running quickly with InstantSearch.js, have a look at the getting started guide.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
const search = instantsearch({
indexName: 'instant_search',
searchClient: algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
),
});
// Add widgets
// ...
search.start();
Options
indexName
|
type: string
Required
The main index to search into. |
||
Copy
|
|||
searchClient
|
type: object
Required
Provides a search client to |
||
Copy
|
|||
numberLocale
|
type: string
Optional
The locale used to display numbers. This is passed to |
||
Copy
|
|||
searchFunction
|
type: function
Optional
A hook that is called each time a search needs to be done, with the helper as a parameter.
It’s your responsibility to call When modifying the state of the helper within |
||
Copy
|
|||
searchParameters
|
type: object
Optional
Additional search parameters to pass to the Algolia API. We recommend using the |
||
Copy
|
|||
stalledSearchDelay
|
type: number
default: 200
Optional
How much time before a search is considered stalled. You can find more information in the slow network guide. |
||
Copy
|
|||
routing
|
type: boolean|object
default: false
Optional
The router configuration used to save the UI state into the URL, or any client-side persistence. You can find more information in the routing guide. The object form accepts two attributes:
|
||
Copy
|
Methods
addWidget
|
Adds a widget. This can be done before and after |
||
Copy
|
|||
addWidgets
|
Adds multiple widgets. This can be done before and after the |
||
Copy
|
|||
start
|
Ends the initialization of |
||
Copy
|
|||
removeWidget
|
Removes a widget. This can be done after the The widget instance to remove from |
||
Copy
|
|||
removeWidgets
|
Removes multiple widgets. This can be done only after the The widgets instances to remove from |
||
Copy
|
|||
dispose
|
Removes all widgets without triggering a search afterwards. This is an experimental feature. If you find an issue with it, please open an issue. |
||
Copy
|
|||
refresh
|
Clears the cached responses from Algolia and triggers a new search. You can find more information in the guide about caching. |
||
Copy
|
Events
render
|
Triggered when the rendering of all the widgets is done. This happens after the search results comes back from Algolia, which means that it is triggered for the first time after all the widgets have been through all their lifecycle steps once ( |
||
Copy
|
|||
error
|
Triggered when an error is reported when calling the API. |
||
Copy
|