configure
instantsearch.widgets.configure(searchParameters: object);
About this widget
The configure
widget lets you provide raw search parameters to the Algolia API without rendering anything.
Any props you add to this widget is forwarded to Algolia. For more information on the different parameters you can set, have a look at the search parameters API reference.
Examples
1
2
3
4
instantsearch.widgets.configure({
hitsPerPage: 8,
enablePersonalization: true,
});
Options
searchParameters
|
type: object
Required
A list of search parameters to enable when the widget mounts. |
||
Copy
|
HTML output
This widget has no HTML output.
Customize the UI - connectConfigure
If you want to create your own UI of the configure
widget, you can use connectors.
It’s a 3-step process:
// 1. Create a render function
const renderConfigure = (renderOptions, isFirstRender) => {
// Rendering logic
};
// 2. Create the custom widget
const customConfigure = instantsearch.connectors.connectConfigure(
renderConfigure
);
// 3. Instantiate
search.addWidgets([
customConfigure({
// instance params
})
]);
Create a render function
This rendering function is called before the first search (init
lifecycle step)
and each time results come back from Algolia (render
lifecycle step).
const renderConfigure = (renderOptions, isFirstRender) => {
const {
function refine,
object widgetParams,
} = renderOptions;
if (isFirstRender) {
// Do some initial rendering and bind events
}
// Render the widget
}
Rendering options
refine
|
type: function
Removes the provided |
||
Copy
|
|||
widgetParams
|
type: object
All original widget options forwarded to the render function. |
||
Copy
|
Create and instantiate the custom widget
We first create custom widgets from our rendering function, then we instantiate them. When doing that, there are two types of parameters you can give:
- Instance parameters: they are predefined parameters that you can use to configure the behavior of Algolia.
- Your own parameters: to make the custom widget generic.
Both instance and custom parameters are available in connector.widgetParams
, inside the renderFunction
.
const customConfigure = instantsearch.connectors.connectConfigure(
renderConfigure
);
search.addWidgets([
customConfigure({
searchParameters: object,
})
]);
Instance options
searchParameters
|
type: object
Required
A list of search parameters to enable when this widget renders. |
||
Copy
|
Full example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Create the render function
const renderConfigure = (renderOptions, isFirstRender) => {
const { refine, widgetParams } = renderOptions;
if (isFirstRender) {
const button = document.createElement('button');
const pre = document.createElement('pre');
button.addEventListener('click', () => {
refine({
hitsPerPage: widgetParams.searchParameters.hitsPerPage === 8 ? 4 : 8,
});
});
widgetParams.container.appendChild(button);
widgetParams.container.appendChild(pre);
}
widgetParams.container.querySelector(
'button'
).textContent = `Sets "hitsPerPage" to ${
widgetParams.searchParameters.hitsPerPage === 8 ? 4 : 8
}`;
widgetParams.container.querySelector('pre').innerHTML = JSON.stringify(
widgetParams.searchParameters,
null,
2
);
};
// Create the custom widget
const customConfigure = instantsearch.connectors.connectConfigure(
renderConfigure,
() => {}
);
// Instantiate the custom widget
search.addWidgets([
customConfigure({
container: document.querySelector('#configure'),
searchParameters: {
hitsPerPage: 8,
},
})
]);