diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/search.js | 20 | ||||
-rw-r--r-- | src/static/js/client.js | 21 | ||||
-rw-r--r-- | src/util/searchSchema.js | 22 |
3 files changed, 29 insertions, 34 deletions
diff --git a/src/search.js b/src/search.js index cb4db7bb..9b5d2d7a 100644 --- a/src/search.js +++ b/src/search.js @@ -8,6 +8,8 @@ import FlexSearch from 'flexsearch'; import {logError, logInfo, logWarn} from '#cli'; import Thing from '#thing'; +import {makeSearchIndexes} from './util/searchSchema.js'; + export async function writeSearchIndex({ wikiCachePath, wikiData, @@ -21,23 +23,7 @@ export async function writeSearchIndex({ // 2. Add documents to index // 3. Save index to exportable json - // Copy this block directly into clientSearch.js - const indexes = { - albums: new FlexSearch.Document({ - id: "reference", - index: ["name", "groups"], - }), - - tracks: new FlexSearch.Document({ - id: "reference", - index: ["name", "album", "artists", "directory", "additionalNames"], - }), - - artists: new FlexSearch.Document({ - id: "reference", - index: ["names"], - }), - }; + const indexes = makeSearchIndexes(FlexSearch); for (const album of wikiData.albumData) { indexes.albums.add({ diff --git a/src/static/js/client.js b/src/static/js/client.js index 075448a8..650a3925 100644 --- a/src/static/js/client.js +++ b/src/static/js/client.js @@ -7,6 +7,9 @@ import {accumulateSum, atOffset, empty, filterMultipleArrays, stitchArrays} from '../shared-util/sugar.js'; + +import FlexSearch from '../lib/flexsearch/flexsearch.bundle.module.min.js'; + import {fetchWithProgress} from './xhr-util.js'; const clientInfo = window.hsmusicClientInfo = Object.create(null); @@ -3419,25 +3422,9 @@ clientSteps.addPageListeners.push(addArtistExternalLinkTooltipPageListeners); // Internal search functionality -------------------------- async function initSearch() { - const {FlexSearch} = window; // Copied directly from server search.js - const indexes = { - albums: new FlexSearch.Document({ - id: "reference", - index: ["name", "groups"], - }), - - tracks: new FlexSearch.Document({ - id: "reference", - index: ["name", "album", "artists", "directory", "additionalNames"], - }), - - artists: new FlexSearch.Document({ - id: "reference", - index: ["names"], - }), - }; + const indexes = makeSearchIndexes(FlexSearch); window.indexes = indexes; diff --git a/src/util/searchSchema.js b/src/util/searchSchema.js new file mode 100644 index 00000000..99ba869a --- /dev/null +++ b/src/util/searchSchema.js @@ -0,0 +1,22 @@ +// Index structures shared by client and server. + +export function makeSearchIndexes(FlexSearch) { + const indexes = { + albums: new FlexSearch.Document({ + id: "reference", + index: ["name", "groups"], + }), + + tracks: new FlexSearch.Document({ + id: "reference", + index: ["name", "album", "artists", "directory", "additionalNames"], + }), + + artists: new FlexSearch.Document({ + id: "reference", + index: ["names"], + }), + }; + + return indexes; +} |