createRecentSearchesPlugin
The Recent Searches plugin displays a list of the latest searches the user made.
The createRecentSearchesPlugin
plugin lets you implement your own storage. To connect with the user's local storage, check createLocalStorageRecentSearchesPlugin
.
#
InstallationFirst, you need to install the plugin.
Then import it in your project:
If you don't use a package manager, you can use a standalone endpoint:
#
ExampleThis example uses the plugin within autocomplete-js
. You're in charge of implementing the storage to fetch and save recent searches.
For example, you can plug it to a MongoDB database using mongoose.
You can combine this plugin with the Query Suggestions plugin to leverage the empty screen with recent and popular queries.
#
Parametersstorage
#
RecentSearchesStorage
| required
The storage to fetch from and save recent searches into.
transformSource
#
(params: { source: AutocompleteSource, onRemove: () => void, onTapAhead: () => void })
A function to transform the provided source.
#
ExamplesKeeping the panel open on select:
Opening a link:
#
Returnsdata
#
getAlgoliaSearchParams
#
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.