createLocalStorageRecentSearchesPlugin plugin connects with the user’s local storage
to fetch and save recent searches.
To use your own storage,
check createRecentSearchesPlugin.
See demo
Installation
First, you need to install the plugin.JavaScript
script element:
HTML
Example
This example uses the plugin withinautocomplete-js.
JavaScript
JavaScript
Parameters
string
required
A local storage key to identify where to save and retrieve the recent searches.For example:
"navbar""search""main"
number
The number of recent searches to display.
(params: { query: string; items: TItem[]; limit: number; }) => TItem[]
A search function to retrieve recent searches from.
This function is called in
storage.getAll
to retrieve recent searches and is useful to filter and highlight recent searches when typing a query.JavaScript
function
Type definition
transformSource to set the isOpen state:JavaScript
AutocompleteRecentSearchesPluginTranslations
Type definition
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 local storage.
(id: string) => void
A function that removes an item from the recent searches local storage.
() => TItem[]
A function that returns the items from the recent searches local storage.