(query)
| 354 | }; |
| 355 | |
| 356 | const performSearch = async (query) => { |
| 357 | const q = query.trim().toLowerCase(); |
| 358 | |
| 359 | if (!q || q.length < 2) { |
| 360 | hideResults(); |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | await loadIndex(); |
| 365 | |
| 366 | if (!docsIndex || docsIndex.length === 0) { |
| 367 | hideResults(); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | const matches = docsIndex |
| 372 | .map((page) => { |
| 373 | const title = (page.title || "").toString(); |
| 374 | const content = (page.content || "").toString(); |
| 375 | const haystack = (title + " " + content).toLowerCase(); |
| 376 | const score = haystack.indexOf(q); |
| 377 | return score === -1 ? null : { page, score }; |
| 378 | }) |
| 379 | .filter(Boolean) |
| 380 | .sort((a, b) => a.score - b.score) |
| 381 | .slice(0, 10) |
| 382 | .map((entry) => entry.page); |
| 383 | |
| 384 | renderResults(matches, q); |
| 385 | }; |
| 386 | |
| 387 | let searchDebounce = null; |
| 388 |
no test coverage detected