From 8e8011d79511d68309d99ea93688d2a64d6149a6 Mon Sep 17 00:00:00 2001 From: Gio Date: Tue, 26 Mar 2024 20:36:24 -0500 Subject: search: minor client refactor --- src/static/js/client.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/static/js') diff --git a/src/static/js/client.js b/src/static/js/client.js index 650a3925..a3d63719 100644 --- a/src/static/js/client.js +++ b/src/static/js/client.js @@ -3426,23 +3426,26 @@ async function initSearch() { // Copied directly from server search.js const indexes = makeSearchIndexes(FlexSearch); - window.indexes = indexes; - const searchData = await fetch('/search-data/index.json') .then(resp => resp.json()); + // If this fails, it's because an outdated index was cached. + // TODO: If this fails, try again once with a cache busting url. for (const [indexName, indexData] of Object.entries(searchData)) { for (const [key, value] of Object.entries(indexData)) { - window.indexes[indexName].import(key, value); + indexes[indexName].import(key, value); } } + + // Expose variable to window + window.searchIndexes = indexes; } function searchAll(query, options = {}) { const results = {}; - for (const [indexName, index] of Object.entries(window.indexes)) { + for (const [indexName, index] of Object.entries(window.searchIndexes)) { results[indexName] = index.search(query, options); } -- cgit 1.3.0-6-gf8a5