Skip to main content
Autocomplete is also available as an experimental widget in InstantSearch, making it easier to integrate into your search experience. For more information, see the API reference for InstantSearch.js or React InstantSearch.
The createRecentSearchesPlugin plugin lets you implement your own storage. To connect with the user’s local storage, check createLocalStorageRecentSearchesPlugin.

Open CodeSandbox

Run and edit the createRecentSearchesPlugin example in CodeSandbox.

Installation

First, you need to install the plugin.
Then import it in your project:
JavaScript
If you don’t use a package manager, you can use the HTML script element:
HTML

Example

This example uses the plugin within autocomplete-js. You’re in charge of implementing the storage to fetch and save recent searches.
JavaScript
For example, you can connect it to a MongoDB database using mongoose.
JavaScript
You can combine this plugin with the Query Suggestions plugin to populate the empty screen with recent and popular queries.
JavaScript

Parameters

RecentSearchesStorage
required
The storage to fetch from and save recent searches into.
TypeScript
function
Type definition
This function takes the original source as a parameter and returns a modified version of that source.Example: change Autocomplete stateUsually, when a link in the Autocomplete menu is selected, the menu closes. However, to keep the menu visible after a selection is made, use transformSource to set the isOpen state:
JavaScript
Example: create linksTurns Query Suggestions into clickable Google search links:
AutocompleteRecentSearchesPluginTranslations
TypeScript
A dictionary of translations to support internationalization.

Returns

data

SearchParameters => SearchParameters
Optimized Algolia search parameters. This is useful when using the plugin along with the Query Suggestions plugin.This function enhances the provided search parameters by:
  • Excluding Query Suggestions that are already displayed in recent searches.
  • Using a shared hitsPerPage value to get a group limit of Query Suggestions and recent searches.
(item: TItem) => void
A function that adds an item to the recent searches storage.
(id: string) => void
A function that removes an item from the recent searches storage.
() => TItem[]
A function that returns the items from the recent searches storage.
Last modified on July 14, 2026