ss-search
Version:
The most basic, yet powerful text search.
22 lines (19 loc) • 1.15 kB
text/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>(elements: T[], searchableKeys: string[], searchText: string, options: {
withScore: true;
cacheKey?: unknown;
}): SearchResultWithScore<T>[];
declare function search<T>(elements: T[], searchableKeys: string[], searchText: string, options?: {
withScore?: false | undefined;
cacheKey?: unknown;
}): T[];
export { type SearchResultWithScore, convertToSearchableStrings, getScore, indexDocuments, normalize, search, tokenize };