/**
 * Search Results Cache
 *
 * Caches search and grep results with file-change-aware invalidation.
 * Key features:
 * - Query normalization for better hit rates
 * - File dependency tracking for invalidation
 * - Concurrent request deduplication
 * - Pattern-based invalidation
 *
 * Search operations are expensive - caching provides significant speedup
 * for repeated queries.
 */
import { EventEmitter } from 'events';
export interface SearchCacheEntry<T = unknown> {
    key: string;
    queryHash: string;
    normalizedQuery: string;
    results: T;
    affectedFiles: string[];
    timestamp: number;
    expiresAt: number;
    hits: number;
    searchType: 'text' | 'file' | 'symbol' | 'reference';
    metadata?: {
        resultCount?: number;
        executionTimeMs?: number;
        options?: Record<string, unknown>;
    };
}
export interface SearchCacheConfig {
    enabled: boolean;
    ttlMs: number;
    maxEntries: number;
    invalidateOnFileChange: boolean;
    deduplicateRequests: boolean;
    normalizeQueries: boolean;
    /** Enable tiered TTL based on result freshness importance */
    tieredTtl: boolean;
    /** TTL for text search (most volatile) */
    textSearchTtlMs: number;
    /** TTL for file search (moderately volatile) */
    fileSearchTtlMs: number;
    /** TTL for symbol search (least volatile) */
    symbolSearchTtlMs: number;
    /** Enable result ranking optimization */
    enableRankingOptimization: boolean;
    /** Minimum execution time to cache (ms) - skip caching fast queries */
    minExecutionTimeToCache: number;
    /** Enable partial match fallback */
    enablePartialMatch: boolean;
    /** Similarity threshold for partial matching */
    partialMatchThreshold: number;
}
export interface SearchCacheStats {
    totalEntries: number;
    hits: number;
    misses: number;
    hitRate: number;
    deduplicatedRequests: number;
    invalidations: number;
    evictions: number;
    byType: {
        text: number;
        file: number;
        symbol: number;
        reference: number;
    };
    /** Partial match hits */
    partialHits: number;
    /** Average execution time saved (ms) */
    avgTimeSavedMs: number;
    /** Total execution time saved (ms) */
    totalTimeSavedMs: number;
    /** Cache efficiency score (0-1) */
    efficiencyScore: number;
}
export declare class SearchResultsCache<T = unknown> extends EventEmitter {
    private cache;
    private config;
    private stats;
    private pendingRequests;
    private fileToKeys;
    private timeSavings;
    private queryFrequency;
    constructor(config?: Partial<SearchCacheConfig>);
    /**
     * Get TTL based on search type
     */
    private getTtlForType;
    /**
     * Get cached search result
     */
    get(query: string, searchType: SearchCacheEntry['searchType'], options?: Record<string, unknown>): T | null;
    /**
     * Find a partial match for a query
     */
    private findPartialMatch;
    /**
     * Record time saved for metrics
     */
    private recordTimeSaved;
    /**
     * Update efficiency score
     */
    private updateEfficiencyScore;
    /**
     * Store search result in cache
     */
    set(query: string, searchType: SearchCacheEntry['searchType'], results: T, options?: {
        affectedFiles?: string[];
        executionTimeMs?: number;
        options?: Record<string, unknown>;
    }): void;
    /**
     * Get or compute search result with deduplication
     */
    getOrCompute(query: string, searchType: SearchCacheEntry['searchType'], computeFn: () => Promise<T>, options?: {
        affectedFiles?: string[];
        options?: Record<string, unknown>;
    }): Promise<{
        results: T;
        cached: boolean;
    }>;
    /**
     * Invalidate cache entries affected by a file change
     */
    invalidateForFile(filePath: string): number;
    /**
     * Invalidate entries matching a pattern
     */
    invalidatePattern(pattern: RegExp): number;
    /**
     * Invalidate entries by search type
     */
    invalidateByType(searchType: SearchCacheEntry['searchType']): number;
    /**
     * Create cache key
     */
    private createKey;
    /**
     * Normalize query for better cache hits
     */
    private normalizeQuery;
    /**
     * Hash string
     */
    private hashString;
    /**
     * Check if entry is expired
     */
    private isExpired;
    /**
     * Remove entry and its file mappings
     */
    private removeEntry;
    /**
     * Add file -> key mapping
     */
    private addFileMapping;
    /**
     * Remove file -> key mapping
     */
    private removeFileMapping;
    /**
     * Evict entries if needed
     */
    private evictIfNeeded;
    /**
     * Evict least recently used entry
     */
    private evictLRU;
    /**
     * Update hit rate statistic
     */
    private updateHitRate;
    /**
     * Get statistics
     */
    getStats(): SearchCacheStats;
    /**
     * Format statistics
     */
    formatStats(): string;
    /**
     * Clear cache
     */
    clear(): void;
    /**
     * Dispose resources
     */
    dispose(): void;
}
export declare function getSearchResultsCache<T = unknown>(config?: Partial<SearchCacheConfig>): SearchResultsCache<T>;
export declare function resetSearchResultsCache(): void;
