Been looking over this a little bit this evening, and I’m not going to say it’s impossible, but I think this is going to be some decent refactoring of our default autocomplete template.
Probably the biggest hurdle at the moment is that we admit that WP Search With Algolia ships with Autocomplete version 0.38, and we haven’t attempted upgrading everyone past version 1.x thus far. This is because they vastly refactored how they handle things.
You can see an upgrade guide for them at https://www.algolia.com/doc/ui-libraries/autocomplete/guides/upgrading/. A quick example of what we need to be careful about is https://www.algolia.com/doc/ui-libraries/autocomplete/guides/upgrading/#container where they went from an <input>
container to just a div and they render the input for you. FWIW, we are aware of the lift to upgrade, and have an open issue over at https://github.com/WebDevStudios/wp-search-with-algolia/issues/232
I was able to confirm that the version of AlgoliaSearch library that we ship with, does have multipleQueries already.
For example I pasted this right after our var client = algoliasearch( ... )
line in the autocomplete.php file, and it showed 1 request against these three indexes specified:
const queries = [{
indexName: 'wp_terms_category',
query : 'hello',
params : {
hitsPerPage: 3
}
}, {
indexName: 'wp_terms_category',
query : 'hello',
params : {
hitsPerPage: 3,
}
}, {
indexName: 'wp_searchable_posts',
query : 'hello',
params : {
hitsPerPage: 3,
}
}];
client.multipleQueries(queries).then(({results}) => {
console.log(results);
});
The next big part that I’m seeing that we don’t have right by default for this would be our sources construction. We’re piecing just the sources to use, and passing in later to be used alongside the query value that gets calculated internally from what I see.
For the code above, we’d need to piece together the queries by specifing the index names to search in, as well as provide the query value ourselves, where we’d then get our response back. Then we need to render those in a template afterwards.
So, not impossible I must believe, but in terms of getting this done asap, it will probably be a case of overriding what we ship by default, and to various degrees overhauling our default autocomplete template to make it work with modern Autocomplete versions.