How to run a 'blank' pre-search with instantSearch.js?


In the algolia-search-helper library, it exists a searchOnce fonction that does not trigger the helper lifecycle and does not modify the state.
I cannot find the function in the instantsearch.js documentation, but I’ve tried to use it via instantseearch.js this way, in a custom widget :

function(error, content, state) {

No error in the console, but searchOnce seems never to call the callback function to deliver the results of the search or an error.

If this is the wrong way, is there a way with instantsearch.js to run a search that has no effects on the search sate and render of the widgets ?
I need to run a with ‘blank’ search’, and then run another one based on the x first hits of the first one.

Thank you in advance for your help,
Have a nice day !


I’m not super knowledgeable about the helper, but if you’re trying to avoid modifying the InstantSearch state, you could just make the query directly from the JavaScript client:

const index = client.initIndex('contacts');

// Search for "query string" in the index "contacts"'query string').then(({ hits }) => {

Hi Chuck,

Thank you for your quick answer :slight_smile: !

Because I work inside an custom instantSearch widget, I’ve implemented your suggestion this way :

const mywidget = {
init: function(params) {
const instantSearchInstance = params.instantSearchInstance;
instantSearchInstance.client.initIndex(instantSearchInstance.indexName).search(‘my query’).then(({ hits }) => {


I hope this implementation is reliable…

But It works great !! Thank you again !

1 Like

If you want to perform a search with no effects on the search state and widget render, you could try using the searchForFacetValues method of the helper object. This method allows you to perform a search for facet values without modifying the current search state.

You can call this method article in your custom widget as follows:

  facetName: 'your_facet_name',
  query: ''
}, function(error, content) {

This will perform a search with a blank query and return the results in the content parameter of the callback function. You can then use the results of this search to perform your second search based on the x first hits.