/** * Literal Index Storage * * Manages the literal index for exact-match boosting. * Handles file I/O for persisting literal data. * * Structure: * .raggrep/index//literals/ * └── _index.json (literal → chunk mappings) */ import type { ExtractedLiteral, DetectedLiteral, LiteralMatch, LiteralIndexEntry } from "../../domain/entities/literal"; /** * Literal Index Manager * * Manages the literal index for exact-match boosting. * Provides O(1) lookup for literal matches. * * Now also supports vocabulary-based search for partial matching: * - Store vocabulary words extracted from literals * - Search by vocabulary words to find partial matches */ export declare class LiteralIndex { private indexPath; private moduleId; /** * In-memory index: lowercase literal value → entries */ private entries; /** * Vocabulary index: vocabulary word → literal values that contain it * Used for partial matching (e.g., "user" → ["getUserById", "fetchUserData"]) */ private vocabularyIndex; /** * Schema version for compatibility checking. */ private static readonly VERSION; constructor(indexDir: string, moduleId: string); /** * Initialize the literal index. * Attempts to load from disk, creates empty index if not found. */ initialize(): Promise; /** * Rebuild the vocabulary index from entries. * Called after loading from disk. */ private rebuildVocabularyIndex; /** * Add literals from a chunk to the index. * * @param chunkId - Unique identifier for the chunk * @param filepath - Path to the file containing the chunk * @param literals - Extracted literals from the chunk */ addLiterals(chunkId: string, filepath: string, literals: ExtractedLiteral[]): void; /** * Remove all literals for a chunk. * * @param chunkId - Chunk ID to remove */ removeChunk(chunkId: string): void; /** * Remove all literals for a file. * Used when a file is re-indexed or deleted. * * @param filepath - Filepath to remove all literals for * @returns Number of literals removed */ removeFile(filepath: string): number; /** * Find matches for query literals. * * @param queryLiterals - Literals detected in the query * @returns Array of matches with chunk IDs and filepaths */ findMatches(queryLiterals: DetectedLiteral[]): LiteralMatch[]; /** * Get all chunk IDs that contain a specific literal. * * @param literal - The literal value to search for * @returns Array of chunk IDs */ getChunksForLiteral(literal: string): string[]; /** * Find literals that contain a specific vocabulary word. * * @param word - The vocabulary word to search for * @returns Array of literal entries that contain this word */ findByVocabulary(word: string): LiteralIndexEntry[]; /** * Find matches for query by vocabulary words. * Returns literals that contain any of the given vocabulary words. * * @param vocabularyWords - Words to search for * @returns Array of matches with overlap information */ findByVocabularyWords(vocabularyWords: string[]): Array<{ entry: LiteralIndexEntry; matchedWords: string[]; }>; /** * Save the index to disk. */ save(): Promise; /** * Load the index from disk. */ load(): Promise; /** * Check if the index exists on disk. */ exists(): Promise; /** * Clear the index. */ clear(): void; /** * Get the number of unique literals in the index. */ get size(): number; /** * Get the total number of literal-to-chunk mappings. */ get totalMappings(): number; /** * Get all unique literals in the index. */ getAllLiterals(): string[]; /** * Build a map from chunk ID to literal matches for a set of query literals. * Convenience method for search integration. * * @param queryLiterals - Literals detected in the query * @returns Map from chunk ID to array of matches */ buildMatchMap(queryLiterals: DetectedLiteral[]): Map; } /** * Get the literal index path for a module. */ export declare function getLiteralIndexPath(rootDir: string, moduleId: string, indexDir?: string): string;