Commit c063faf1e1

c063faf1e1e747856c36b73d0da1355d1f57be53

parent: 59e2770299

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-31 10:19 UTC

Update Search.vue

Layout: unified · split

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