Start algolia search on specific event

I would like to control by myself when the search has to start.
This means, after the user enter the search term, i would like to verify the search term. After my action, i like to start algolia search.
By the option “searchOnEnterKeyPressOnly: true” i can only stop the auto search, but the algolia search will be started immediately.
Can i start my action before algolia search?

Hi @j.czembor,

Thanks for contacting Algolia.

From your description, it sounds like the option to hit enter with “searchOnEnterKeyPressOnly: true” is not what you want. It sounds like you want to intercept and check the search with some function/method of your choice. Is that right?

If this is the case, some customers take the step of “intercepting” the InstantSearch in the searchFunction parameter to only fire when the query matches their need.

For inspiration, here is an example. If the query is not empty or on X number of characters we trigger the search. You can leverage the Helper.js library which is already available in InstantSearch to check the query like this:

var search = instantsearch({      
// other search parameters    
searchFunction: function(helper) {         
    if (helper.state.query.length == 0) {             
        return; // no search         
    } ; // trigger search     

I hope this provides some inspiration and direction for your need. Let us know how it goes.

It works fine.
Thank You :slight_smile: