(event)
| 596 | } |
| 597 | } |
| 598 | async function handleSearch(event) { |
| 599 | event.preventDefault(); |
| 600 | const query = document.getElementById("query").value.trim(); |
| 601 | if (!query) return; |
| 602 | const minRatio = parseInt(document.getElementById("minRatio").value) || 50; |
| 603 | const minSimilarity = |
| 604 | parseFloat(document.getElementById("minSimilarity").value) || 0; |
| 605 | const searchForm = document.getElementById("searchForm"); |
| 606 | searchForm.classList.add("searching"); |
| 607 | startNaturalLoadingBar(); |
| 608 | |
| 609 | try { |
| 610 | const results = await SearchController.performSearch( |
| 611 | query, |
| 612 | minRatio, |
| 613 | minSimilarity, |
| 614 | ); |
| 615 | |
| 616 | if (results && results.status === "success") { |
| 617 | AppState.cachedResults = results.data; |
| 618 | AppState.hasMoreResults = results.data.length > AppState.itemsPerPage; |
| 619 | AppState.displayedCount = 0; |
| 620 | |
| 621 | displayResults(results); |
| 622 | completeLoadingBar(); |
| 623 | } else { |
| 624 | throw new Error("Invalid search results format"); |
| 625 | } |
| 626 | } catch (error) { |
| 627 | console.error("Search error:", error); |
| 628 | document.getElementById("errorDisplay").textContent = |
| 629 | `搜索失败: ${error.message}`; |
| 630 | document.getElementById("errorDisplay").style.display = "block"; |
| 631 | completeLoadingBar(); |
| 632 | } finally { |
| 633 | enableKeywordTags(); |
| 634 | searchForm.classList.remove("searching"); |
| 635 | } |
| 636 | } |
| 637 | async function initializeApp() { |
| 638 | try { |
| 639 | await dbStorage.init().catch((error) => {}); |
no test coverage detected