The Search API Autocomplete module adds autocomplete functionality to Search API searches. Autocomplete only works for servers that support it, and currently, only the Solr and database service classes are known to support this feature. In this video, I will show you how to setup Search API Autocomplete, to add the autocomplete functionality to our site.

Install Module

Enable Module

  • Go to "Modules" (admin/modules) and enable:
    • Search API autocomplete
  • (Save Configuration)

After having installed and enabled the Search API Autocomplete module, we'll have to enable the autocomplete function for our search index.

Configure Autocomplete

  • Go to "Configuration = > Search and Metadata => Search API (admin/config/search/search_api)
  • Node index
    • Click "dropdown" arrow
    • Choose "Autocomplete"

On this page we have to enable the search form(s) that should use the autocomplete function. Let's enable autocomplete for the Search View.

  • Search Views
    • [x] Search View
  • (Save)

Then, we need to configure the Search View.

  • Search Views
    • Click "edit"
    • [x] Display result count estimates (This displays the estimated number of results for each suggested keywords)
  • Views display: Page
  • (Save)

There are also a couple of configuration options in the Search Server.

  • Go to "Configuration = > Search and Metadata => Search API (admin/config/search/search_api)
  • Apache Solr Search Server
    • Click "Edit"
    • Expand the "Advanced" section to find a new "Autocomplete" section
    • Expand "Autocomplete"
      • [x] Use spellcheck for autocomplete suggestions (This will use spellcheck when typing and off "Did you mean" suggestions. As it mentions, the dictionary uses words from all indexes, so if you have sensitive data in one of your indexes, those terms may be suggested to users.)
      • [x] Suggest additional words (Once the user has entered a complete word, this will suggest additional words that are often found together. This can cause some some strange word combinations, so if you have issues with that, you might want to disable this option.)

Lastly, we need to set some permissions in order for users to have access to the autocomplete functionality.

Configure permissions

  • Go to "People => Permissions"
  • Scroll down to Search API autocomplete
  • Grant "Use autocomplete for the Search View search" to:
    • [x] Anonymous user
    • [x] Authenticated user
  • (Save permissions)

Now, let's go to the home page and search for an article title. Notice that as you type it gives you a list of autocomplete suggestions and the number of items for each suggested keywords.