import { SearchHit, WeightedHit, SearchSpec } from './types'; declare type SearchScore = [number, string]; /** * Calculates a score (between 0 and 1) indicating general search relevance of an array of * search tokens within a specific string. * * @param searchTerms - All search terms * @param value - The string to match against * @returns A [score, story] pair containing the search score as well as a human readable explanation * @internal */ export declare const calculateScore: (searchTerms: string[], value: string) => SearchScore; /** * Applies path weights from a supplied SearchSpec to existing search hits to create _weighted_ hits * augmented with search ranking and human readable explanations. * * @param searchSpec - SearchSpec containing path weighting * @param hits - SearchHit objects to augment * @param terms - All search terms * @returns WeightedHit array containing search scores and ranking explanations * @internal */ export declare function applyWeights(searchSpec: SearchSpec[], hits: SearchHit[], terms?: string[]): WeightedHit[]; /** * For phrases: score on the total number of matching characters. * E.g. given the phrases ["the fox", "of london"] for the target value "the wily fox of london" * * - "the fox" isn't included in the target value (score: 0) * - "of london" is included in the target value, and 9 out of 22 characters match (score: 9/22 = ~0.408) * - non-exact matches have their score divided in half (final score: ~0.204) * * @param uniqueSearchPhrases - All search phrases * @param value - The string to match against * @returns SearchScore containing the search score as well as a human readable explanation * @internal */ export declare function calculatePhraseScore(uniqueSearchPhrases: string[], value: string): SearchScore; /** * For words: score on the total number of matching words. * E.g. given the terms ["bar", "fo"] for the target value "food bar". * * - "fo" is included in the target value, and 2 out of 7 non-whitespace characters match (score: 2/7) * - "bar" is included in the target value, and 3 out of 7 non-whitespace characters match (score: 3/7) * - all values are accumulated and have their score devidied by half (final score: ~0.357) * * @param uniqueSearchTerms - A string array of search terms * @param value - The string to match against * @returns SearchScore containing the search score as well as a human readable explanation * @internal */ export declare function calculateCharacterScore(uniqueSearchTerms: string[], value: string): SearchScore; /** * Generate a score on the total number of matching _whole_ words. * E.g. given the words ["the", "fox", "of", "london"] for the target value "the wily fox of london" * * - 4 out of 5 words match (score: 4/5 = 0.8) * - non-exact matches have their score divided in half (final score: 0.4) * * @param uniqueSearchTerms - All search terms * @param value - The string to match against * @returns SearchScore containing the search score as well as a human readable explanation * @internal */ export declare function calculateWordScore(uniqueSearchTerms: string[], value: string): SearchScore; /** * Partition search terms by phrases (wrapped with quotes) and words. * * @param searchTerms - All search terms * @returns Partitioned phrases and words * @internal */ export declare function partitionAndSanitizeSearchTerms(searchTerms: string[]): { phrases: string[]; words: string[]; }; /** * Returns matching array indices of `values` containing _any_ member of `uniqueSearchTerms`. * When comparing for matches, members of `values` are stringified, trimmed and lowercased. * * @param uniqueSearchTerms - All search terms * @param values - Values to match against (members are stringified) * @returns All matching indices in `values` * @internal */ export declare function findMatchingIndices(uniqueSearchTerms: string[], values: unknown[]): number[]; export {}; //# sourceMappingURL=applyWeights.d.ts.map