/** * @file * Search helpers that extend keyword tokenization with scoring and ranking across name, keyword, and * description fields. Use these utilities when you need ordered results; use `filter` for * simple include/exclude filtering without relevance scoring. */ type SearchableProperties = { name: string; keywords?: string; description?: string; }; type SearchData = { nameLower: string; keywordsLower?: string; descriptionLower?: string; }; type ItemWithSearchData = T & { searchData: SearchData; }; type SearchScoreValue = (typeof SEARCH_SCORE)[keyof typeof SEARCH_SCORE]; type ItemWithSearchScore = ItemWithSearchData & { searchScore: SearchScore; }; /** * Constants used for scoring search matches. * Higher scores indicate better matches. */ declare const SEARCH_SCORE: { /** * Exact match */ readonly EXACT: 100; /** * Case insensitive substring */ readonly SUBSTR: 10; /** * No match found */ readonly NONE: 0; }; type SearchScore = { hasMatch: boolean; nameScore: SearchScoreValue; nameMatchPosition: number; keywordsScore: SearchScoreValue; descriptionScore: SearchScoreValue; }; declare const getSearchResultScore: (filter: string, searchData: SearchData) => SearchScore; declare const rankItems: (items: Array>) => Array>; /** * Returns a new array of items with each item containing precomputed search data to be used with `search`. * @param {Array} items - Each item must have `name`. Optionally, they can have `keywords` or `description` properties. * @returns {Array} A new array of items, each augmented with `searchData` properties * @public */ declare function addSearchData(items: T[]): ItemWithSearchData[]; /** * Returns filtered and sorted list of data based on provided search term. * * @param {Array} data - The array of items to search. Each item must include `searchData` property (use `addSearchData` to add it). * @param {String} filter - The search term to filter and rank the data by. * @returns {Array} An array of items that match the search term, sorted by relevance. * @public */ declare function search>(filter: string, data: Array): Array; export type { SearchData, ItemWithSearchData, ItemWithSearchScore }; export { addSearchData, search, getSearchResultScore, rankItems };