Custom Source from combined queries

this was useful to start thinking about how to combine multiple queries into a single data source to be used in autocomplete. However the below code gets results in the post request but not in the callback function(results) or suggestions. What am I missing here? Thanks in advance.

  	source: 	function(query, callback) {
  		algolia_client.search(
  			queries,
  			function (results) {
  				var hits;
  				if (results == null) {
  					hits = {};
  				} else {
  					hits = results.length > 0 ? results[0] : {};
  					hits = results.length > 1 ? hits.concat(results[1].hits) : hits;
  				}

  				callback(hits);
  			}
  		);
  	},

I should also mention that my goal is to return categories that have products matching the autocomplete query. My plan is to add a query in the queries array for each category, then combine them and display a category only if it returned a result.

Of course as soon as I post this I try the right thing.

My function(results) needed to be replaced with this:

(err, { results } = {}) => {
if (err) throw err;

callback(results);
}

Hah, that’s always how it works, isn’t it. Thanks very much for posting the solution here so that others can benefit from it!