{"version":3,"file":"searchFunctions.mjs","sources":["../../../src/utils/searchFunctions.ts"],"sourcesContent":["import { CompletionItem, SearchFunction } from '../types';\n\nimport { fuzzyMatch } from './fuzzy';\n\n/**\n * List of auto-complete search function used by SuggestionsPlugin.handleTypeahead()\n * @alpha\n */\nexport enum SearchFunctionType {\n  Word = 'Word',\n  Prefix = 'Prefix',\n  Fuzzy = 'Fuzzy',\n}\n\n/**\n * Exact-word matching for auto-complete suggestions.\n * - Returns items containing the searched text.\n * @internal\n */\nconst wordSearch: SearchFunction = (items: CompletionItem[], text: string): CompletionItem[] => {\n  return items.filter((c) => (c.filterText || c.label).includes(text));\n};\n\n/**\n * Prefix-based search for auto-complete suggestions.\n * - Returns items starting with the searched text.\n * @internal\n */\nconst prefixSearch: SearchFunction = (items: CompletionItem[], text: string): CompletionItem[] => {\n  return items.filter((c) => (c.filterText || c.label).startsWith(text));\n};\n\n/**\n * Fuzzy search for auto-complete suggestions.\n * - Returns items containing all letters from the search text occurring in the same order.\n * - Stores highlight parts with parts of the text phrase found by fuzzy search\n * @internal\n */\nconst fuzzySearch: SearchFunction = (items: CompletionItem[], text: string): CompletionItem[] => {\n  text = text.toLowerCase();\n  return items.filter((item) => {\n    const { distance, ranges, found } = fuzzyMatch(item.label.toLowerCase(), text);\n    if (!found) {\n      return false;\n    }\n    item.sortValue = distance;\n    item.highlightParts = ranges;\n    return true;\n  });\n};\n\n/**\n * @internal\n */\nexport const SearchFunctionMap = {\n  [SearchFunctionType.Word]: wordSearch,\n  [SearchFunctionType.Prefix]: prefixSearch,\n  [SearchFunctionType.Fuzzy]: fuzzySearch,\n};\n"],"names":["SearchFunctionType"],"mappings":";;AAQY,IAAA,kBAAA,qBAAAA,mBAAL,KAAA;AACL,EAAAA,oBAAA,MAAO,CAAA,GAAA,MAAA;AACP,EAAAA,oBAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,oBAAA,OAAQ,CAAA,GAAA,OAAA;AAHE,EAAAA,OAAAA,mBAAAA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