/** * @fileoverview Type definitions for the search engine module. * Provides interfaces for indexing items and search operations. */ /** * Represents an indexed item ready for searching. * Contains pre-computed normalized text and tokens for performance. */ export interface IndexedItem { /** Unique identifier for the item */ id: string; /** Original label text */ label: string; /** Normalized version of the label (lowercase, no accents, etc.) */ norm: string; /** Tokenized version of the normalized label */ tokens: string[]; } /** * Represents the result of a search operation. */ export interface SearchResult { /** Array of matching item IDs */ ids: string[]; /** Total number of matches before truncation */ total: number; /** Whether results were truncated due to maxResults limit */ truncated: boolean; } /** * Filter mode for search operations. * - 'strict': Simple substring matching (normalized includes) * - 'smart': Token-based matching (all query tokens must exist, order ignored) * - 'fuzzy': Typo-tolerant matching using Fuse.js (runs in Web Worker) */ export type FilterMode = 'strict' | 'smart' | 'fuzzy'; /** * Options for search operations. */ export interface SearchOptions { /** The search query string */ query: string; /** Filter mode to use for matching */ filterMode: FilterMode; /** Maximum number of results to return (default: 200, hard cap: 500) */ maxResults?: number; /** Minimum query length before filtering starts (default: 0) */ startFilterAt?: number; /** Threshold for fuzzy matching (0-1, lower = stricter, default: 0.3) */ fuzzyThreshold?: number; } /** * Raw item input for building the search index. */ export interface RawItem { /** Unique identifier for the item */ id: string; /** Display label for the item */ label: string; } /** * Message types for Web Worker communication. */ export type WorkerMessageType = 'INIT' | 'SEARCH' | 'RESULT' | 'ERROR'; /** * Message sent to the search worker. */ export interface WorkerRequest { /** Message type for the worker request */ type: 'INIT' | 'SEARCH'; /** Unique identifier for request tracking */ requestId: string; /** Request payload data */ payload: WorkerInitPayload | WorkerSearchPayload; } /** * Payload for initializing the worker with items. */ export interface WorkerInitPayload { /** Items to index in the worker */ items: RawItem[]; } /** * Payload for search requests. */ export interface WorkerSearchPayload { /** Search query string */ query: string; /** Filter mode to use */ filterMode: FilterMode; /** Maximum results to return */ maxResults: number; /** Fuzzy matching threshold */ fuzzyThreshold: number; } /** * Response from the search worker. */ export interface WorkerResponse { /** Response type */ type: 'RESULT' | 'ERROR'; /** Request ID for matching responses */ requestId: string; /** Response payload with results or error */ payload: SearchResult | { error: string; }; }