I've been following the example for Algolia's Instant Search at https://www.algolia.com/doc/guides/search/instant-search/ (javascript version)
I understand that for many use-cases (like in the example) it makes sense for the script to run its initial search upon pageload and display the results (basically all results). In my case though I'd like to not do that initial search. How can I achieve this?
Thanks
You can pass a searchFunction
parameter to the instantsearch
initializer, which will intercept each search and let you decide whether to perform it or not.
Here's an example taken from this Github issue. The search is not performed if the query is empty, as it will be on page load.
var search = instantsearch({
searchFunction: function(helper) {
if (helper.state.query === '') {
return;
}
helper.search();
}
});
If you have your own logic around when the search should/shouldn't be performed you can use it in here. See the Usage tab of the Initialization section of the docs for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With