diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-26 21:23:14 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-31 12:11:44 -0300 |
commit | b537d4e1369d494a9cb2454086a47b507097b367 (patch) | |
tree | f0960c38e3742701c1580c1ff2a9ec7af044bd8b | |
parent | 1daf5caea096b3160ebc51c43eda633f1059e2be (diff) |
client, search: move search functions into main client3.js file
-rw-r--r-- | src/static/clientSearch.js | 45 | ||||
-rw-r--r-- | src/static/js/client.js | 48 |
2 files changed, 48 insertions, 45 deletions
diff --git a/src/static/clientSearch.js b/src/static/clientSearch.js deleted file mode 100644 index a10d3855..00000000 --- a/src/static/clientSearch.js +++ /dev/null @@ -1,45 +0,0 @@ -/* eslint-env browser */ - -async function initSearch() { - const {FlexSearch} = window; - - // Copied directly from server search.js - window.indexes = { - albums: new FlexSearch.Document({ - id: "reference", - index: ["name", "groups"], - }), - - tracks: new FlexSearch.Document({ - id: "reference", - index: ["track", "album", "artists", "directory", "additionalNames"], - }), - - artists: new FlexSearch.Document({ - id: "reference", - index: ["names"], - }), - }; - - const searchData = - await fetch('/search-data/index.json') - .then(resp => resp.json()); - - for (const [indexName, indexData] of Object.entries(searchData)) { - for (const [key, value] of Object.entries(indexData)) { - window.indexes[index_key].import(key, value); - } - } -} - -function searchAll(query, options = {}) { - const results = {}; - - for (const [indexName, index] of Object.entries(window.indexes)) { - results[indexName] = index.search(query, options); - } - - return results; -} - -document.addEventListener('DOMContentLoaded', initSearch); diff --git a/src/static/js/client.js b/src/static/js/client.js index 5ff3ab9a..3df0d585 100644 --- a/src/static/js/client.js +++ b/src/static/js/client.js @@ -3416,6 +3416,54 @@ clientSteps.getPageReferences.push(getArtistExternalLinkTooltipPageReferences); clientSteps.addInternalListeners.push(addArtistExternalLinkTooltipInternalListeners); clientSteps.addPageListeners.push(addArtistExternalLinkTooltipPageListeners); +// Internal search functionality -------------------------- + +async function initSearch() { + const {FlexSearch} = window; + + // Copied directly from server search.js + window.indexes = { + albums: new FlexSearch.Document({ + id: "reference", + index: ["name", "groups"], + }), + + tracks: new FlexSearch.Document({ + id: "reference", + index: ["track", "album", "artists", "directory", "additionalNames"], + }), + + artists: new FlexSearch.Document({ + id: "reference", + index: ["names"], + }), + }; + + const searchData = + await fetch('/search-data/index.json') + .then(resp => resp.json()); + + for (const [indexName, indexData] of Object.entries(searchData)) { + for (const [key, value] of Object.entries(indexData)) { + window.indexes[index_key].import(key, value); + } + } +} + +function searchAll(query, options = {}) { + const results = {}; + + for (const [indexName, index] of Object.entries(window.indexes)) { + results[indexName] = index.search(query, options); + } + + return results; +} + +document.addEventListener('DOMContentLoaded', initSearch); + +window.searchAll = searchAll; + // Sticky commentary sidebar ------------------------------ const albumCommentarySidebarInfo = initInfo('albumCommentarySidebarInfo', { |