« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/search.js9
-rw-r--r--src/static/js/client.js8
2 files changed, 10 insertions, 7 deletions
diff --git a/src/search.js b/src/search.js
index 7dcf5cf9..cb4db7bb 100644
--- a/src/search.js
+++ b/src/search.js
@@ -30,7 +30,7 @@ export async function writeSearchIndex({
 
     tracks: new FlexSearch.Document({
       id: "reference",
-      index: ["track", "album", "artists", "directory", "additionalNames"],
+      index: ["name", "album", "artists", "directory", "additionalNames"],
     }),
 
     artists: new FlexSearch.Document({
@@ -50,7 +50,7 @@ export async function writeSearchIndex({
       indexes.tracks.add({
         reference: Thing.getReference(track),
         album: album.name,
-        track: track.name,
+        name: track.name,
 
         artists: [
           track.artistContribs.map(contrib => contrib.artist.name),
@@ -75,14 +75,15 @@ export async function writeSearchIndex({
   }
 
   // Export indexes to json
-  const searchData = {}
+  const searchData = {};
 
+  // Map each index to an export promise, and await all.
   await Promise.all(
     Object.entries(indexes)
       .map(([indexName, index]) => {
         searchData[indexName] = {};
         return index.export((key, data) => {
-          searchData[indexName][key] = data
+          searchData[indexName][key] = data;
         });
       }));
 
diff --git a/src/static/js/client.js b/src/static/js/client.js
index 3df0d585..075448a8 100644
--- a/src/static/js/client.js
+++ b/src/static/js/client.js
@@ -3422,7 +3422,7 @@ async function initSearch() {
   const {FlexSearch} = window;
 
   // Copied directly from server search.js
-  window.indexes = {
+  const indexes = {
     albums: new FlexSearch.Document({
       id: "reference",
       index: ["name", "groups"],
@@ -3430,7 +3430,7 @@ async function initSearch() {
 
     tracks: new FlexSearch.Document({
       id: "reference",
-      index: ["track", "album", "artists", "directory", "additionalNames"],
+      index: ["name", "album", "artists", "directory", "additionalNames"],
     }),
 
     artists: new FlexSearch.Document({
@@ -3439,13 +3439,15 @@ async function initSearch() {
     }),
   };
 
+  window.indexes = indexes;
+
   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);
+      window.indexes[indexName].import(key, value);
     }
   }
 }