
Open CodeSandbox
Run and edit the Autocomplete with Federated Search example in CodeSandbox.
View code on GitHub
View the Autocomplete with Federated Search example code on GitHub.
Before you begin
This tutorial extends Build a Query Suggestions UI with Autocomplete.Combine different data sources
With different indices for different content types, you can optimize the relevance for each type. For example, blog posts might require a different ranking strategy than products. Federated search can search multiple indices simultaneously and show the results in the same interface. You can combine data sources in four different ways:Implement federated search
You can add multiple data sources to Autocomplete withgetSources. In this tutorial, Autocomplete uses these data sources:
- Query Suggestions from the index
instant_search_demo_query_suggestions - Product catalog from the index
instant_search - Hierarchical product categories from
instant_search
Add Query Suggestions as first data source
Follow the steps in Adding Query Suggestions to set upautocomplete-plugin-query-suggestions.
Add search results for products as second data source
First, importgetAlgoliaResults from the autocomplete-js package to get results from an Algolia index.
JavaScript
getSources and getAlgoliaResults to get matching products from the Algolia index instant_search. This example uses custom rendering with Preact components.
JavaScript
Add product categories as third data source
To add categories to the federated search, importgetAlgoliaFacets from autocomplete-js.
JavaScript
getAlgoliaFacets to getSources to add the product categories:
JavaScript
Next steps
Beyond this example, you can add more data sources. To make your data sources reusable and shareable, encapsulate them as plugins. For more information, see Build your own plugin. You can also add more features, such as:- Merchandising. Use Rules and merchandising to promote queries or items in the empty-search state or no-results state.
- Personalization. Use Algolia’s personalization feature to enhance Query Suggestions or products.
- Dynamic Re-ranking. Let Algolia’s Dynamic Re-ranking feature boost popular Query Suggestions or products.