question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getAlgoliaResults(...).then is not a function

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Haroenvcommented, Jun 7, 2021

That example is indeed wrong

2reactions
sarahdayancommented, Jun 9, 2021

When using getAlgoliaFacets and getAlgoliaResults 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found