diff options
-rw-r--r-- | src/search.js | 45 | ||||
-rwxr-xr-x | src/upd8.js | 4 |
2 files changed, 30 insertions, 19 deletions
diff --git a/src/search.js b/src/search.js index 9b5d2d7a..4a711b23 100644 --- a/src/search.js +++ b/src/search.js @@ -10,21 +10,8 @@ import Thing from '#thing'; import {makeSearchIndexes} from './util/searchSchema.js'; -export async function writeSearchIndex({ - wikiCachePath, - wikiData, -}) { - if (!wikiCachePath) { - throw new Error(`Expected wikiCachePath to write into`); - } - - // Basic flow is: - // 1. Define schema for type - // 2. Add documents to index - // 3. Save index to exportable json - - const indexes = makeSearchIndexes(FlexSearch); - +async function populateSearchIndexes(indexes, wikiData) { + // Albums, tracks for (const album of wikiData.albumData) { indexes.albums.add({ reference: Thing.getReference(album), @@ -35,8 +22,8 @@ export async function writeSearchIndex({ for (const track of album.tracks) { indexes.tracks.add({ reference: Thing.getReference(track), - album: album.name, name: track.name, + album: album.name, artists: [ track.artistContribs.map(contrib => contrib.artist.name), @@ -49,6 +36,7 @@ export async function writeSearchIndex({ } } + // Artists for (const artist of wikiData.artistData) { if (artist.isAlias) { continue; @@ -60,7 +48,8 @@ export async function writeSearchIndex({ }); } - // Export indexes to json + +async function exportIndexesToJson(indexes) { const searchData = {}; // Map each index to an export promise, and await all. @@ -73,6 +62,28 @@ export async function writeSearchIndex({ }); })); + return searchData; +} + +export async function writeSearchJson({ + wikiCachePath, + wikiData, +}) { + if (!wikiCachePath) { + throw new Error(`Expected wikiCachePath to write into`); + } + + // Basic flow is: + // 1. Define schema for type + // 2. Add documents to index + // 3. Save index to exportable json + + const indexes = makeSearchIndexes(FlexSearch); + + await populateSearchIndexes(indexes, wikiData); + + const searchData = await exportIndexesToJson(indexes); + const outputDirectory = path.join(wikiCachePath, 'search'); diff --git a/src/upd8.js b/src/upd8.js index 3dc01da8..21cabfae 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -47,7 +47,7 @@ import {bindFind, getAllFindSpecs} from '#find'; import {processLanguageFile, watchLanguageFile, internalDefaultStringsFile} from '#language'; import {isMain, traverse} from '#node-utils'; -import {writeSearchIndex} from '#search' +import {writeSearchJson} from '#search'; import {sortByName} from '#sort'; import {generateURLs, urlSpec} from '#urls'; import {identifyAllWebRoutes} from '#web-routes'; @@ -1489,7 +1489,7 @@ async function main() { timeStart: Date.now(), }); - await writeSearchIndex({ + await writeSearchJson({ wikiCachePath, wikiData, }); |