Home > widget-integration > RecentSearchService
RecentSearchService class
Service for managing recent searches in localStorage.
Technical Support teams can extend this service for custom storage strategies:
Signature:
export declare class RecentSearchService
Example 1
window.boostWidgetIntegration.extend('RecentSearchService', (RecentSearchService) => {
return class CustomRecentSearchService extends RecentSearchService {
// Use session storage instead of local storage
protected getStorage() {
return sessionStorage;
}
};
});
Example 2
// Access the service via module
const recentSearchService = window.boostISWModule.recentSearchService;
// Get recent searches
const searches = recentSearchService.getRecentSearches(5);
// Add a recent search
recentSearchService.addRecentSearch('blue shoes');
// Clear all searches
recentSearchService.clearRecentSearches();
Constructors
|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Constructs a new instance of the |
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
| |||
|
|
boolean |
Enable debug logging | |
|
|
(not declared) |
Maximum number of recent searches to store | |
|
|
(not declared) |
LocalStorage key for recent searches |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
Add a search term to recent searches. **Legacy**: setOnClickRecentSearches(item, extraParam, scope) **New**: addRecentSearch(query, extraParam, scope) with deduplication Features: - Moves duplicate searches to the top (case-insensitive) - Trims whitespace from query - Limits storage to MAX_ITEMS | ||
|
Clear all recent searches. **Legacy**: Not available **New**: Added for better UX | ||
|
Get the count of recent searches. | ||
|
Get recent searches from localStorage. **Legacy**: getOnClickRecentSearches(maxRecentSearch) **New**: getRecentSearches(limit) with proper typing | ||
|
Get recent search titles as a simple string array. | ||
|
|
Get the storage instance to use. Override this method to use a different storage strategy. | |
|
Handle click events on suggestion terms and popular searches. Extracts the search term from clicked elements and saves it to recent searches. **Legacy**: handleRecentSearchForSuggestionTerm(event) **New**: handleSuggestionTermClick(event) with proper typing | ||
|
Check if a search term exists in recent searches. | ||
|
|
Log a debug message when debug mode is enabled. | |
|
Remove a specific search from recent searches. **Legacy**: Not available **New**: Added for better UX | ||
|
Enable or disable debug mode for logging. |