diff --git a/.nojekyll b/.nojekyll index 0cc9e3a..00eb591 100644 --- a/.nojekyll +++ b/.nojekyll @@ -1 +1 @@ -15c66c27 \ No newline at end of file +fc15bd82 \ No newline at end of file diff --git a/about.html b/about.html index 2daf8ac..d278472 100644 --- a/about.html +++ b/about.html @@ -2,7 +2,7 @@ - + @@ -295,6 +295,7 @@ const links = window.document.querySelectorAll("a"); for (let i = 0; i < links.length; i++) { if (links[i].href) { + links[i].dataset.originalHref = links[i].href; links[i].href = links[i].href.replace(/\/index\.html/, "/"); } } @@ -1050,6 +1051,18 @@ // create the index var fuseIndex = undefined; var shownWarning = false; + +// fuse index options +const kFuseIndexOptions = { + keys: [ + { name: "title", weight: 20 }, + { name: "section", weight: 20 }, + { name: "text", weight: 10 }, + ], + ignoreLocation: true, + threshold: 0.1, +}; + async function readSearchData() { // Initialize the search index on demand if (fuseIndex === undefined) { @@ -1060,17 +1073,7 @@ shownWarning = true; return; } - // create fuse index - const options = { - keys: [ - { name: "title", weight: 20 }, - { name: "section", weight: 20 }, - { name: "text", weight: 10 }, - ], - ignoreLocation: true, - threshold: 0.1, - }; - const fuse = new window.Fuse([], options); + const fuse = new window.Fuse([], kFuseIndexOptions); // fetch the main search.json const response = await fetch(offsetURL("search.json")); @@ -1601,8 +1604,34 @@ }); } -function fuseSearch(query, fuse, fuseOptions) { - return fuse.search(query, fuseOptions).map((result) => { +let subSearchTerm = undefined; +let subSearchFuse = undefined; +const kFuseMaxWait = 125; + +async function fuseSearch(query, fuse, fuseOptions) { + let index = fuse; + // Fuse.js using the Bitap algorithm for text matching which runs in + // O(nm) time (no matter the structure of the text). In our case this + // means that long search terms mixed with large index gets very slow + // + // This injects a subIndex that will be used once the terms get long enough + // Usually making this subindex is cheap since there will typically be + // a subset of results matching the existing query + if (subSearchFuse !== undefined && query.startsWith(subSearchTerm)) { + // Use the existing subSearchFuse + index = subSearchFuse; + } else if (subSearchFuse !== undefined) { + // The term changed, discard the existing fuse + subSearchFuse = undefined; + subSearchTerm = undefined; + } + + // Search using the active fuse + const then = performance.now(); + const resultsRaw = await index.search(query, fuseOptions); + const now = performance.now(); + + const results = resultsRaw.map((result) => { const addParam = (url, name, value) => { const anchorParts = url.split("#"); const baseUrl = anchorParts[0]; @@ -1619,6 +1648,17 @@ crumbs: result.item.crumbs, }; }); + + // If we don't have a subfuse and the query is long enough, go ahead + // and create a subfuse to use for subsequent queries + if (now - then > kFuseMaxWait && subSearchFuse === undefined) { + subSearchTerm = query; + subSearchFuse = new window.Fuse([], kFuseIndexOptions); + resultsRaw.forEach((rr) => { + subSearchFuse.add(rr.item); + }); + } + return results; } @@ -4621,7 +4661,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + - + - + @@ -4578,7 +4618,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - + @@ -4579,7 +4619,7 @@ .bi-suitcase2::before { content: "\f902"; } .bi-vignette::before { content: "\f903"; } - +