
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:Data sources | Example |
---|---|
Two or more Algolia indices | One index for Query Suggestions, another for products, and another for a blog. Each index has different data types, data structures, and ranking strategies. |
One Algolia index with different filters | You can apply filters to contextualize and get extra data sets from the same index. For example, if your index has both movies and books, you can query a single index twice: one query with a filter for “movies” and the second query for “books”. |
One Algolia index and filter values from the same index | In a “product” index, you can have a set of category filters. You can apply these category filters and return relevant category values. |
One Algolia index and third-party data | You can search both an Algolia index and a third-party API asynchronously. For example, you can search into an Algolia index of restaurants and get a list of nearby addresses using the Google Places API. |
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.