wp-search-with-algolia icon indicating copy to clipboard operation
wp-search-with-algolia copied to clipboard

Autocomplete doesn't handle multiple queries correctly

Open jasonbarry96 opened this issue 4 years ago • 2 comments

Describe the bug If you select multiple indices to be used in autocomplete, each index is queried in a separate request. Algolia's current pricing model charges by the individual network request. So every time a search is performed in an autocomplete with 2+ indices, the charges will be multiplied.

The problematic code is here.

To resolve this, we should be creating the hits using autocomplete sources. See the example code here.

Expected behavior If an autocomplete queries 2+ indices, each keystroke should trigger one single network request. Each request will be an array of queries. See more info about Algolia multi-queries here.

jasonbarry96 avatar Oct 25 '21 20:10 jasonbarry96

We noticed this as well. It looks like the autocomplete hits source no longer works with the latest version of algoliasearch (v4) though (see note https://github.com/algolia/autocomplete/tree/v0.38.0#standalone), although I didn't test it to see for sure, I just assumed it wouldn't.

We instead went the route of using the multipleQueries API and used our own response "cache" to prevent query from running more than once per character entered.

Full code here as an example. It doesn't cover every case, but it works well enough for us now.

coreyworrell avatar Apr 17 '23 18:04 coreyworrell

Thanks for sharing this @coreyworrell

tw2113 avatar Apr 17 '23 20:04 tw2113