/** * Full-text search operations: tokenization, matching, and relevance scoring. * * Provides pure functions for text search functionality including * tokenization, stop word filtering, and relevance-based ranking. */ /** * Tokenize text into normalized tokens. * * Splits on whitespace, strips leading/trailing punctuation characters, * lowercases all tokens, and filters out empty strings. * * @param text - The text to tokenize * @returns Array of normalized tokens * * @example * ```ts * tokenize("Gibson, William") * // => ["gibson", "william"] * * tokenize("The Left Hand of Darkness") * // => ["the", "left", "hand", "of", "darkness"] * * tokenize(" ") * // => [] * * tokenize("") * // => [] * ``` */ export declare function tokenize(text: string): ReadonlyArray; /** * Tokenize text with optional stop word filtering. * * Calls `tokenize` then optionally filters out common stop words * (articles, prepositions, conjunctions, etc.) that typically don't * contribute to search relevance. * * @param text - The text to tokenize * @param removeStopWords - Whether to filter out stop words * @returns Array of normalized tokens, optionally without stop words * * @example * ```ts * tokenizeWithStopWords("The Left Hand of Darkness", false) * // => ["the", "left", "hand", "of", "darkness"] * * tokenizeWithStopWords("The Left Hand of Darkness", true) * // => ["left", "hand", "darkness"] * ``` */ export declare function tokenizeWithStopWords(text: string, removeStopWords: boolean): ReadonlyArray; /** * Compute the relevance score for a single field value against query tokens. * * Scoring uses three factors combined multiplicatively: * 1. **Term coverage**: Fraction of query tokens that matched (0..1) * 2. **Term frequency (TF)**: How many times query tokens appear in the field * 3. **Field length normalization**: Shorter fields score higher for same match * * Prefix matches (via startsWith) count toward matching but score slightly lower * than exact matches to preserve ranking quality. * * @param fieldValue - The field value to score * @param queryTokens - The tokenized search query * @returns Relevance score (0 if no tokens match) * * @example * ```ts * computeFieldScore("Dune", ["dune"]) * // => ~1.44 (exact match, short field) * * computeFieldScore("The Left Hand of Darkness", ["left", "hand"]) * // => ~0.29 (2/2 coverage, longer field) * * computeFieldScore("Neuromancer", ["neuro"]) * // => ~0.72 (prefix match, reduced score) * * computeFieldScore("Dune", ["xyz"]) * // => 0 (no match) * ``` */ export declare function computeFieldScore(fieldValue: string, queryTokens: ReadonlyArray): number; /** * Compute the total relevance score for an entity across multiple fields. * * Sums the field scores for all specified fields. Fields that are not * present on the entity or are not strings are skipped (score 0). * * @param entity - The entity to score * @param queryTokens - The tokenized search query * @param fields - The fields to search across * @returns Total relevance score (0 if no fields match) * * @example * ```ts * const book = { title: "Dune", author: "Frank Herbert", year: 1965 } * * computeSearchScore(book, ["dune"], ["title", "author"]) * // => ~1.44 (matches in title only) * * computeSearchScore(book, ["herbert", "dune"], ["title", "author"]) * // => ~2.88 (matches in both fields) * * computeSearchScore(book, ["xyz"], ["title", "author"]) * // => 0 (no matches) * ``` */ export declare function computeSearchScore(entity: Record, queryTokens: ReadonlyArray, fields: ReadonlyArray): number; //# sourceMappingURL=search.d.ts.map