| @@ -654,16 +654,17 @@ watch( |
| 654 | () => |
654 | () => |
| 655 | [ |
655 | [ |
| 656 | searchWorkerReady.value, |
656 | searchWorkerReady.value, |
| |
657 | showSearch.value, |
| 657 | urlSearchMode.value, |
658 | urlSearchMode.value, |
| 658 | urlFilterDebounced.value |
659 | urlFilterDebounced.value |
| 659 | ] as const, |
660 | ] as const, |
| 660 | async ([ready, active, query], _old, onCleanup) => { |
661 | async ([ready, isOpen, active, query], _old, onCleanup) => { |
| 661 | let canceled = false |
662 | let canceled = false |
| 662 | onCleanup(() => { |
663 | onCleanup(() => { |
| 663 | canceled = true |
664 | canceled = true |
| 664 | }) |
665 | }) |
| 665 | |
666 | |
| 666 | if (!active || !query.trim()) { |
667 | if (!active || !isOpen || !query.trim()) { |
| 667 | urlMatches.value = [] |
668 | urlMatches.value = [] |
| 668 | urlPageGroupCounts.value = [] |
669 | urlPageGroupCounts.value = [] |
| 669 | return |
670 | return |
| @@ -691,7 +692,17 @@ watch( |
| 691 | ) |
692 | ) |
| 692 | |
693 | |
| 693 | function getPageKey(id: string) { |
694 | function getPageKey(id: string) { |
| 694 | return id.split('#')[0].replace(/\/$/, '') |
695 | return getDocId(id).replace(/\/$/, '') |
| |
696 | } |
| |
697 | |
| |
698 | function getDocId(id: string) { |
| |
699 | const hashIndex = id.indexOf('#') |
| |
700 | return hashIndex === -1 ? id : id.slice(0, hashIndex) |
| |
701 | } |
| |
702 | |
| |
703 | function getDocAnchor(id: string) { |
| |
704 | const hashIndex = id.indexOf('#') |
| |
705 | return hashIndex === -1 ? '' : id.slice(hashIndex + 1) |
| 695 | } |
706 | } |
| 696 | |
707 | |
| 697 | function getPageLabel(key: string) { |
708 | function getPageLabel(key: string) { |
| @@ -1014,6 +1025,7 @@ watchDebounced( |
| 1014 | () => |
1025 | () => |
| 1015 | [ |
1026 | [ |
| 1016 | searchWorkerReady.value, |
1027 | searchWorkerReady.value, |
| |
1028 | showSearch.value, |
| 1017 | localeIndex.value, |
1029 | localeIndex.value, |
| 1018 | searchIndexVersion.value, |
1030 | searchIndexVersion.value, |
| 1019 | searchWorkerConfigKey.value, |
1031 | searchWorkerConfigKey.value, |
| @@ -1024,6 +1036,7 @@ watchDebounced( |
| 1024 | async ( |
1036 | async ( |
| 1025 | [ |
1037 | [ |
| 1026 | ready, |
1038 | ready, |
| |
1039 | isOpen, |
| 1027 | localeIndexValue, |
1040 | localeIndexValue, |
| 1028 | indexVersion, |
1041 | indexVersion, |
| 1029 | configKey, |
1042 | configKey, |
| @@ -1035,9 +1048,9 @@ watchDebounced( |
| 1035 | onCleanup |
1048 | onCleanup |
| 1036 | ) => { |
1049 | ) => { |
| 1037 | if ( |
1050 | if ( |
| 1038 | old?.[1] !== localeIndexValue || |
1051 | old?.[2] !== localeIndexValue || |
| 1039 | old?.[2] !== indexVersion || |
1052 | old?.[3] !== indexVersion || |
| 1040 | old?.[3] !== configKey |
1053 | old?.[4] !== configKey |
| 1041 | ) { |
1054 | ) { |
| 1042 | // Locale/config changes rebuild the worker index, so cached excerpts may no |
1055 | // Locale/config changes rebuild the worker index, so cached excerpts may no |
| 1043 | // longer match the active result set. |
1056 | // longer match the active result set. |
| @@ -1049,13 +1062,21 @@ watchDebounced( |
| 1049 | canceled = true |
1062 | canceled = true |
| 1050 | }) |
1063 | }) |
| 1051 | |
1064 | |
| 1052 | if (!ready) return |
1065 | if (!ready || !isOpen) return |
| 1053 | |
1066 | |
| 1054 | // In URL search mode, skip normal text search |
1067 | // In URL search mode, skip normal text search |
| 1055 | if (mode === 'url') { |
1068 | if (mode === 'url') { |
| 1056 | results.value = [] |
1069 | results.value = [] |
| 1057 | currentTerms.value = new Set() |
1070 | currentTerms.value = new Set() |
| 1058 | enableNoResults.value = true |
1071 | enableNoResults.value = Boolean(filterTextValue.trim()) |
| |
1072 | return |
| |
1073 | } |
| |
1074 | |
| |
1075 | const searchQuery = filterTextValue.trim() |
| |
1076 | if (!searchQuery) { |
| |
1077 | results.value = [] |
| |
1078 | currentTerms.value = new Set() |
| |
1079 | enableNoResults.value = false |
| 1059 | return |
1080 | return |
| 1060 | } |
1081 | } |
| 1061 | |
1082 | |
| @@ -1080,7 +1101,7 @@ watchDebounced( |
| 1080 | |
1101 | |
| 1081 | workerPayload = await postSearchWorker<TextSearchWorkerPayload>({ |
1102 | workerPayload = await postSearchWorker<TextSearchWorkerPayload>({ |
| 1082 | type: 'text-search', |
1103 | type: 'text-search', |
| 1083 | query: filterTextValue, |
1104 | query: searchQuery, |
| 1084 | mode, |
1105 | mode, |
| 1085 | pageOrderEntries: getPageOrderEntries() |
1106 | pageOrderEntries: getPageOrderEntries() |
| 1086 | }) |
1107 | }) |
| @@ -1107,8 +1128,9 @@ watchDebounced( |
| 1107 | |
1128 | |
| 1108 | const toRows = (list: (SearchResult & Result)[]) => |
1129 | const toRows = (list: (SearchResult & Result)[]) => |
| 1109 | list.map((r) => { |
1130 | list.map((r) => { |
| 1110 | const [id, anchor] = r.id.split('#') |
1131 | const id = getDocId(r.id) |
| 1111 | const map = cache.get(`${id}\n${filterTextValue}`) |
1132 | const anchor = getDocAnchor(r.id) |
| |
1133 | const map = cache.get(`${id}\n${searchQuery}`) |
| 1112 | return { ...r, text: map?.get(anchor) ?? '' } |
1134 | return { ...r, text: map?.get(anchor) ?? '' } |
| 1113 | }) |
1135 | }) |
| 1114 | |
1136 | |
| @@ -1130,7 +1152,7 @@ watchDebounced( |
| 1130 | const docOrderList: string[] = [] |
1152 | const docOrderList: string[] = [] |
| 1131 | const seenDocs = new Set<string>() |
1153 | const seenDocs = new Set<string>() |
| 1132 | for (const r of _result) { |
1154 | for (const r of _result) { |
| 1133 | const docId = r.id.slice(0, r.id.indexOf('#')) |
1155 | const docId = getDocId(r.id) |
| 1134 | if (!seenDocs.has(docId)) { |
1156 | if (!seenDocs.has(docId)) { |
| 1135 | seenDocs.add(docId) |
1157 | seenDocs.add(docId) |
| 1136 | docOrderList.push(docId) |
1158 | docOrderList.push(docId) |
| @@ -1144,10 +1166,10 @@ watchDebounced( |
| 1144 | if (showDetailedListValue) { |
1166 | if (showDetailedListValue) { |
| 1145 | const eagerDocs = new Set<string>() |
1167 | const eagerDocs = new Set<string>() |
| 1146 | for (const r of _result.slice(0, EAGER_EXCERPTS)) { |
1168 | for (const r of _result.slice(0, EAGER_EXCERPTS)) { |
| 1147 | eagerDocs.add(r.id.slice(0, r.id.indexOf('#'))) |
1169 | eagerDocs.add(getDocId(r.id)) |
| 1148 | } |
1170 | } |
| 1149 | await Promise.all( |
1171 | await Promise.all( |
| 1150 | [...eagerDocs].map((docId) => buildDocExcerpt(docId, filterTextValue)) |
1172 | [...eagerDocs].map((docId) => buildDocExcerpt(docId, searchQuery)) |
| 1151 | ) |
1173 | ) |
| 1152 | if (canceled) return |
1174 | if (canceled) return |
| 1153 | } |
1175 | } |
| @@ -1169,12 +1191,12 @@ watchDebounced( |
| 1169 | if (showDetailedListValue) { |
1191 | if (showDetailedListValue) { |
| 1170 | const built = new Set<string>() |
1192 | const built = new Set<string>() |
| 1171 | for (const r of _result.slice(0, EAGER_EXCERPTS)) { |
1193 | for (const r of _result.slice(0, EAGER_EXCERPTS)) { |
| 1172 | built.add(r.id.slice(0, r.id.indexOf('#'))) |
1194 | built.add(getDocId(r.id)) |
| 1173 | } |
1195 | } |
| 1174 | const remaining = docOrderList.filter((d) => !built.has(d)) |
1196 | const remaining = docOrderList.filter((d) => !built.has(d)) |
| 1175 | if (remaining.length) { |
1197 | if (remaining.length) { |
| 1176 | for (const docId of remaining) { |
1198 | for (const docId of remaining) { |
| 1177 | await buildDocExcerpt(docId, filterTextValue) |
1199 | await buildDocExcerpt(docId, searchQuery) |
| 1178 | if (canceled) return |
1200 | if (canceled) return |
| 1179 | await nextFrame() |
1201 | await nextFrame() |
| 1180 | if (canceled) return |
1202 | if (canceled) return |
| @@ -1254,8 +1276,7 @@ onBeforeUnmount(() => { |
| 1254 | const excerptCache = new LRUCache<string, unknown>(24) |
1276 | const excerptCache = new LRUCache<string, unknown>(24) |
| 1255 | |
1277 | |
| 1256 | async function fetchExcerpt(id: string) { |
1278 | async function fetchExcerpt(id: string) { |
| 1257 | const hashIndex = id.indexOf('#') |
1279 | const docId = getDocId(id) |
| 1258 | const docId = hashIndex === -1 ? id : id.slice(0, hashIndex) |
| |
| 1259 | |
1280 | |
| 1260 | const cached = excerptCache.get(docId) |
1281 | const cached = excerptCache.get(docId) |
| 1261 | if (cached) return { id, mod: cached } |
1282 | if (cached) return { id, mod: cached } |