Skip to main content
When your user interacts with a search box, you can help them discover what they could search for by providing Query suggestions. Query suggestions are a specific kind of multi-index interface:
  • The main search interface will use a regular index.
  • As users type a phrase, suggestions from your Query Suggestions index are displayed.

Usage

To display the suggestions:
  • Create a Query Suggestions index from your main index.
  • Implement a Multi-Index search experience using both indices.
  • When clicking on a suggestion, set the query to the chosen suggestion.

Before you begin

To use InstantSearch Android, you need an Algolia account. Either create a new account or use the following credentials:
  • Application ID: latency
  • Search API key: afc3dd66dd1293e2e2736a5a51b05c0a
  • Results index name: STAGING_native_ecom_demo_products
  • Suggestions index name: STAGING_native_ecom_demo_products_query_suggestions
These credentials give you access to pre-existing datasets of products and Query Suggestions appropriate for this guide.

Project structure

Algolia’s query suggestions uses:
  • QuerySuggestionGuide: main activity presenting the search experience,
  • SuggestionFragment: fragment presenting the Query Suggestions,
  • ProductFragment: fragment presenting the search results,
  • QuerySuggestionViewModel: view model holding connectors and search business logic.
The initial screen shows the search box and results for an empty query: Initial state of the search interface on Android showing the search box and the results for an empty search query. When users tap the search box, a list of query suggestions are shown (the most popular for an empty query): List of popular query suggestions in the search interface on Android. On each keystroke, the list of suggestions is updated: The list of Query Suggestions updates on every keystroke. When users select a suggestion from the list, it replaces the query in the search box, and the suggestions fragment disappears. The products fragment presents search results for the selected query suggestion: After accepting a query suggestion the results of the search are shown. Algolia doesn’t provide a ready-to-use views, but you can create them with the tools in the InstantSearch Android library.

Business logic

Create QuerySuggestionViewModel view to setup the search components and create the necessary connections between them, establishing the business logic:
Kotlin

Products view

Create Product data class corresponding the index hits:
Kotlin
Create ProductAdapter to display search results:
Kotlin
Create ProductFragment to display product search results:
Kotlin

Suggestions view

Create Suggestion data class corresponding the suggestions index hits:
Kotlin
Create SuggestionAdapter to display suggestions list:
Kotlin
Create SuggestionFragment to display suggestions’ recycler view adapter, and to notify QuerySuggestionViewModel when a suggestion selection is made:
Kotlin

Setup layout

Finally, create QuerySuggestionActivity activity, and display ProductFragment and SuggestionFragment on SearchBox
Kotlin

Going further

Your query suggestions search experience is now ready to use. You can find a complete project in the Android examples repository.
Last modified on July 21, 2026