ss-search
Version:
The most basic, yet powerful text search.
18 lines (15 loc) • 1.05 kB
TypeScript
import * as lodash from 'lodash';
declare const normalize: (text: string | undefined) => string;
declare const tokenize: (searchText: string | undefined) => string[];
declare const convertToSearchableStrings: (<T>(elements: T[] | null, searchableKeys: string[] | null, cacheKey: unknown | null) => string[]) & lodash.MemoizedFunction;
declare const indexDocuments: (<T>(elements: T[] | null, searchableKeys: string[] | null, cacheKey: unknown | null) => string[]) & lodash.MemoizedFunction;
declare const getScore: (matchesAllSearchWords: boolean, searchWords: string[], searchableDataString: string) => number;
type SearchResultWithScore<T> = {
element: T;
score: number;
};
declare function search<T, TWithScore extends boolean>(elements: T[], searchableKeys: string[], searchText: string, options?: {
withScore?: TWithScore;
cacheKey?: unknown;
}): TWithScore extends true ? SearchResultWithScore<T>[] : T[];
export { type SearchResultWithScore, convertToSearchableStrings, getScore, indexDocuments, normalize, search, tokenize };