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 {
3939 Delete,
4040 File,
4141 Hash,
42 Regex,
42 Locate,
43 LocateOff,
4344 TextAlignStart
4445} from 'lucide-vue-next'
4546import Mark from 'mark.js/dist/mark.es6.js'
@@ -111,12 +112,6 @@ const searchIndex = computedAsync(async () =>
111112 fields: ['title', 'titles', 'text'],
112113 storeFields: ['title', 'titles'],
113114 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,
120115 boost: { title: 10, titles: 4, text: 1 },
121116 ...(theme.value.search?.provider === 'local' &&
122117 theme.value.search.options?.miniSearch?.searchOptions)
@@ -147,7 +142,7 @@ const showDetailedList = useLocalStorage(
147142
148143const matchExact = useLocalStorage(
149144 'vitepress:local-search-match-exact',
150 false // disabled by default
145 true // enabled by default
151146)
152147
153148const disableDetailedView = computed(() => {
@@ -373,8 +368,8 @@ const mark = computedAsync(async () => {
373368const cache = new LRUCache<string, Map<string, string>>(16) // 16 files
374369
375370watchDebounced(
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) => {
378373 if (old?.[0] !== index) {
379374 // in case of hmr
380375 cache.clear()
@@ -387,12 +382,20 @@ watchDebounced(
387382
388383 if (!index) return
389384
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
390392 // Search
391 const ranked = index.search(filterTextValue) as (SearchResult & Result)[]
393 const ranked = index.search(filterTextValue, dynamicSearchOptions) as (SearchResult & Result)[]
392394
393395 // Guaranteed heading matches: any section whose own heading (title)
394396 // contains the term should always show, regardless of score or cap.
395397 const titleHits = index.search(filterTextValue, {
398 ...dynamicSearchOptions,
396399 fields: ['title']
397400 }) as (SearchResult & Result)[]
398401
@@ -730,7 +733,7 @@ onKeyStroke('Escape', () => {
730733const defaultTranslations = {
731734 modal: {
732735 displayDetails: 'Display detailed list',
733 exactMatchTitle: 'Match exact phrases',
736 exactMatchTitle: 'Exact search',
734737 resetButtonTitle: 'Reset search',
735738 backButtonTitle: 'Close search',
736739 noResultsText: 'No results for',
@@ -892,7 +895,8 @@ function onMouseMove(e: MouseEvent) {
892895 :title="translate('modal.exactMatchTitle')"
893896 @click="matchExact = !matchExact"
894897 >
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" />
896900 </button>
897901 <button
898902 class="clear-button"