Commit c063faf1e1
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/Search.vue +17 −13
| @@ -39,7 +39,8 @@ import { | ||
| 39 | 39 | Delete, |
| 40 | 40 | File, |
| 41 | 41 | Hash, |
| 42 | Regex, | |
| 42 | Locate, | |
| 43 | LocateOff, | |
| 43 | 44 | TextAlignStart |
| 44 | 45 | } from 'lucide-vue-next' |
| 45 | 46 | import Mark from 'mark.js/dist/mark.es6.js' |
| @@ -111,12 +112,6 @@ const searchIndex = computedAsync(async () => | ||
| 111 | 112 | fields: ['title', 'titles', 'text'], |
| 112 | 113 | storeFields: ['title', 'titles'], |
| 113 | 114 | searchOptions: { |
| 114 | // Conditional fuzzy search based on matchExact value | |
| 115 | fuzzy: matchExact.value ? false : 0.07, | |
| 116 | // Conditional prefix search based on matchExact value | |
| 117 | prefix: matchExact.value ? false : (term) => term.length > 3, | |
| 118 | // Disable max fuzzy if match exact is enabled | |
| 119 | maxFuzzy: matchExact.value ? 0 : 1, | |
| 120 | 115 | boost: { title: 10, titles: 4, text: 1 }, |
| 121 | 116 | ...(theme.value.search?.provider === 'local' && |
| 122 | 117 | theme.value.search.options?.miniSearch?.searchOptions) |
| @@ -147,7 +142,7 @@ const showDetailedList = useLocalStorage( | ||
| 147 | 142 | |
| 148 | 143 | const matchExact = useLocalStorage( |
| 149 | 144 | 'vitepress:local-search-match-exact', |
| 150 | false // disabled by default | |
| 145 | true // enabled by default | |
| 151 | 146 | ) |
| 152 | 147 | |
| 153 | 148 | const disableDetailedView = computed(() => { |
| @@ -373,8 +368,8 @@ const mark = computedAsync(async () => { | ||
| 373 | 368 | const cache = new LRUCache<string, Map<string, string>>(16) // 16 files |
| 374 | 369 | |
| 375 | 370 | watchDebounced( |
| 376 | () => [searchIndex.value, filterText.value, showDetailedList.value] as const, | |
| 377 | async ([index, filterTextValue, showDetailedListValue], old, onCleanup) => { | |
| 371 | () => [searchIndex.value, filterText.value, showDetailedList.value, matchExact.value] as const, | |
| 372 | async ([index, filterTextValue, showDetailedListValue, matchExactValue], old, onCleanup) => { | |
| 378 | 373 | if (old?.[0] !== index) { |
| 379 | 374 | // in case of hmr |
| 380 | 375 | cache.clear() |
| @@ -387,12 +382,20 @@ watchDebounced( | ||
| 387 | 382 | |
| 388 | 383 | if (!index) return |
| 389 | 384 | |
| 385 | // Dynamic search options based on matchExact toggle | |
| 386 | const dynamicSearchOptions = { | |
| 387 | fuzzy: matchExactValue ? false : (0.07 as number | false), | |
| 388 | prefix: matchExactValue ? false : (term: string) => term.length > 3, | |
| 389 | maxFuzzy: matchExactValue ? 0 : 1, | |
| 390 | } | |
| 391 | ||
| 390 | 392 | // Search |
| 391 | const ranked = index.search(filterTextValue) as (SearchResult & Result)[] | |
| 393 | const ranked = index.search(filterTextValue, dynamicSearchOptions) as (SearchResult & Result)[] | |
| 392 | 394 | |
| 393 | 395 | // Guaranteed heading matches: any section whose own heading (title) |
| 394 | 396 | // contains the term should always show, regardless of score or cap. |
| 395 | 397 | const titleHits = index.search(filterTextValue, { |
| 398 | ...dynamicSearchOptions, | |
| 396 | 399 | fields: ['title'] |
| 397 | 400 | }) as (SearchResult & Result)[] |
| 398 | 401 | |
| @@ -730,7 +733,7 @@ onKeyStroke('Escape', () => { | ||
| 730 | 733 | const defaultTranslations = { |
| 731 | 734 | modal: { |
| 732 | 735 | displayDetails: 'Display detailed list', |
| 733 | exactMatchTitle: 'Match exact phrases', | |
| 736 | exactMatchTitle: 'Exact search', | |
| 734 | 737 | resetButtonTitle: 'Reset search', |
| 735 | 738 | backButtonTitle: 'Close search', |
| 736 | 739 | noResultsText: 'No results for', |
| @@ -892,7 +895,8 @@ function onMouseMove(e: MouseEvent) { | ||
| 892 | 895 | :title="translate('modal.exactMatchTitle')" |
| 893 | 896 | @click="matchExact = !matchExact" |
| 894 | 897 | > |
| 895 | <Regex :size="19" stroke-width="1.25" /> | |
| 898 | <Locate v-if="matchExact" :size="19" stroke-width="1.25" /> | |
| 899 | <LocateOff v-else :size="19" stroke-width="1.25" /> | |
| 896 | 900 | </button> |
| 897 | 901 | <button |
| 898 | 902 | class="clear-button" |