« 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/static/js/client.js2
-rw-r--r--src/util/search-spec.js55
2 files changed, 57 insertions, 0 deletions
diff --git a/src/static/js/client.js b/src/static/js/client.js
index e570b91a..cd5aeea8 100644
--- a/src/static/js/client.js
+++ b/src/static/js/client.js
@@ -3667,6 +3667,8 @@ function clearSidebarSearch() {
 function showSidebarSearchResults(results) {
   const info = sidebarSearchInfo;
 
+  console.debug(`Showing search results:`, results);
+
   const flatResults =
     Object.entries(results)
       .flatMap(([index, results]) => results
diff --git a/src/util/search-spec.js b/src/util/search-spec.js
index b26869a2..decfec7a 100644
--- a/src/util/search-spec.js
+++ b/src/util/search-spec.js
@@ -1,6 +1,61 @@
 // Index structures shared by client and server, and relevant interfaces.
 
 export const searchSpec = {
+  generic: {
+    query: ({
+      albumData,
+      artistData,
+      flashData,
+      trackData,
+    }) => [
+      albumData,
+
+      artistData
+        .filter(artist => !artist.isAlias),
+
+      flashData,
+
+      trackData
+        // Exclude rereleases - there's no reasonable way to differentiate
+        // them from the main release as part of this query.
+        .filter(track => !track.originalReleaseTrack),
+    ].flat(),
+
+    process: (thing) => ({
+      primaryName:
+        thing.name,
+
+      additionalNames:
+        (Object.hasOwn(thing, 'additionalNames')
+          ? thing.additionalNames.map(entry => entry.name)
+       : Object.hasOwn(thing, 'aliasNames')
+          ? thing.aliasNames
+          : []),
+
+      contributors:
+        ([
+          'artistContribs',
+          'bannerArtistContribs',
+          'contributorContribs',
+          'coverArtistContribs',
+          'wallpaperArtistContribs',
+        ]).filter(key => Object.hasOwn(thing, key))
+          .flatMap(key => thing[key])
+          .map(contrib => contrib.artist)
+          .flatMap(artist => [artist.name, ...artist.aliasNames]),
+    }),
+
+    index: [
+      'primaryName',
+      'additionalNames',
+      'contributors',
+    ],
+
+    store: [
+      'primaryName',
+    ],
+  },
+
   albums: {
     query: ({albumData}) => albumData,