« get me outta code hell

search: 'generic' index for like comparisons - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-03 16:59:30 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-31 12:11:49 -0300
commit5bcf13ab09dca78c8bafa151b1ba7e2003e21b56 (patch)
tree5d4f84675c4214943e5a4a52115b739081a80b1a /src/util
parent39fc3d74b1e7e193442ab77962935fb50a593c5d (diff)
search: 'generic' index for like comparisons
Diffstat (limited to 'src/util')
-rw-r--r--src/util/search-spec.js55
1 files changed, 55 insertions, 0 deletions
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,