Home > widget-integration > InstantSearchService
InstantSearchService class
Service for instant search business logic.
Technical Support teams can extend this service for custom search behavior:
Signature:
export declare class InstantSearchService
Example
window.boostWidgetIntegration.extend('InstantSearchService', (InstantSearchService) => {
return class CustomSearchService extends InstantSearchService {
// Filter products before rendering — preferred extension point
protected filterWidgetProducts(products, searchSettings) {
const available = products.filter(p => p.available);
return super.filterWidgetProducts(available, searchSettings);
}
};
});
Constructors
|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Constructs a new instance of the |
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
|
AbortController | null |
Current search abort controller | |
|
| |||
|
|
(not declared) |
Debounce delay in milliseconds | |
|
|
ReturnType<typeof setTimeout> | null |
Debounce timer ID | |
|
|
boolean |
Debug mode flag | |
|
| |||
|
| |||
|
|
(not declared) |
localStorage key for analytics pre-request IDs. | |
|
| |||
|
| |||
|
|
Record<string, string> | null |
Cached redirects map | |
|
|
(not declared) |
localStorage key for suggestion data caching. | |
|
|
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
Add recent search entry. | ||
|
|
Apply shop-specific product filters after base price transformation. Second-level extension hook called by | |
|
|
Check if all visible suggestion blocks are empty. | |
|
|
Cache suggestion data in localStorage for analytics. **Legacy**: setLocalStorage(SUGGESTION_DATA, { query, id, suggestions }) **New**: Dedicated method with typed structure | |
|
Cancel any pending debounced search. | ||
|
Check if query should redirect. **Legacy**: Inline check in handleRedirect() **New**: Dedicated method with type safety | ||
|
Clear all recent searches. | ||
|
Clear redirects cache to force re-fetch. | ||
|
Cleanup resources. | ||
|
|
Filter and transform products for display. Extension point for TS teams to add shop-specific product filtering. The base implementation transforms product prices via **Legacy**: | |
|
Get cached suggestion data from localStorage. | ||
|
Build default suggestion data for initial state. **Legacy**: buildDefaultDataSuggestion(context) **New**: getDefaultSuggestionData(searchSettings) with typed return | ||
|
|
Get price formatting settings from theme configuration. | |
|
Get recent searches. | ||
|
Get redirect mappings. | ||
|
Generate search page URL. **Legacy**: generateSearchPageHref(term, extraParam) **New**: getSearchPageUrl(query, extraParams) with proper encoding | ||
|
Get suggested products for search box on-click. **Legacy**: getSuggestProducts(context) **New**: getSuggestProducts(searchSettings) with typed return | ||
|
|
Handle no-results scenario by fetching fallback products. | |
|
Handle redirect if query matches. | ||
|
|
Log debug messages when debug mode is enabled. | |
|
Merge default data with search response for rendering. | ||
|
|
Process bundle data from search response. **Legacy**: Inline bundle processing with volumeBundleData/dynamicBundleData **New**: Delegated to bundle services (when integrated) | |
|
|
Process widget configuration before use. Extension point for TS teams to customise search settings on a per-shop basis before any search or default-data operations begin. | |
|
Render suggestions using template. | ||
|
|
Save request ID to localStorage for analytics tracking. Stores the API request ID under the **Legacy**: | |
|
Execute search immediately. **Legacy**: requestSuggestion(context, query) **New**: search(query, searchSettings) with typed response | ||
|
Execute search with debouncing. **Legacy**: requestSuggestionDebounce() using debounce utility **New**: Method with built-in debouncing and Promise support | ||
|
Enable or disable debug logging. | ||
|
Transform product prices for display. **Legacy**: transformProductPrice(context, products) **New**: transformProductPrices(products, searchSettings) using AppService | ||
|
|
Validate suggestion data before caching or rendering. Extension point for TS teams to add custom validation rules. Return |