getAlgoliaResults(...).then is not a function
See original GitHub issueDescription
I get the following error: getAlgoliaResults(…).then is not a function
When I try to do the following: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#using-multiple-sources
Reproduction
import algoliasearch from "algoliasearch/lite";
import { getAlgoliaResults } from "@algolia/autocomplete-preset-algolia";
const searchClient = algoliasearch(
"xxxxxxxxxxx",
"xxxxxxxxxxxxx"
);
export const pluginAlgoliaIndexes = {
getSources({ query }) {
console.log(query);
return getAlgoliaResults({
searchClient,
queries: [
{
indexName: "USA Regions",
query,
},
{
indexName: "TroopDocumentation",
query,
},
],
}).then((results) => {
const [suggestions, products] = results;
return [
{
sourceId: "USARegions",
getItems() {
return suggestions.hits;
},
getItemInputValue() {
return item.query;
},
onActive({ item, setContext }) {
item.type = "Region";
setContext({ preview: item });
},
},
{
sourceId: "TroopDocumentation",
getItems() {
return products.hits;
},
getItemUrl({ item }) {
return item.url;
},
},
];
});
},
};
Environment
- Autocomplete version: [e.g. 1.1.0]
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
getAlgoliaResults (presets) | Autocomplete | Algolia
The getAlgoliaResults function lets you query one or several Algolia indices. Using getAlgoliaResults lets Autocomplete batch all queries ...
Read more >TypeError: Prismic.getApi is not a function - Stack Overflow
i'm really struggling while trying to build a website from scratch without a framework. And now i'm integrating Prismic in through node. js, ......
Read more >JavaScript Autocomplete - Learn With Jason
You have a get items function that returns items, so an array of items, and then we're going to provide templates so we...
Read more >Build Typeahead Experiences With Algolia Autocomplete.js ...
In less than 60 lines of code, we have an autocomplete typeahead experience ... lang.js rewritten as a standalone\n* function (not on Function.prototype)....
Read more >Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError- Some selector is not a function - jQuery is not a function - owlCarousel is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That example is indeed wrong
When using
getAlgoliaFacets
andgetAlgoliaResults
with the same search client in different sources or plugins, Autocomplete batches all queries into a single network call to Algolia.So, for example, let’s say you have as-you-type search with two sources that target two different Algolia indices on the same Algolia application (using the same search client). If you type “apple” letter by letter, you’ll generate five search requests instead of ten. Make sure to use the same client instance to leverage the internal cache and batching mechanism.
You can see it for yourself in this sandbox that queries three Algolia indices (including two from plugins): every time you type a character in the input, it generates one XHR request to Algolia, and the response contains the data for all three sources.