From a2a4b8b566114cecb2fd9d3d5a9e0351e521f0f9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 3 Nov 2025 14:20:54 -0400 Subject: search: first try at artist groups --- src/search-select.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'src/search-select.js') diff --git a/src/search-select.js b/src/search-select.js index 4d4ed63e..db347914 100644 --- a/src/search-select.js +++ b/src/search-select.js @@ -3,6 +3,7 @@ // These files totally go together, so read them side by side, okay? import baseSearchSpec from '#search-shape'; +import {unique} from '#sugar'; import {getKebabCase} from '#wiki-data'; function prepareArtwork(artwork, thing, { @@ -52,6 +53,48 @@ function prepareArtwork(artwork, thing, { return serializeSrc; } +function determineArtistGroups(artist, opts) { + const contributions = [ + ...artist.musicContributions, + ...artist.artworkContributions, + ]; + + const contributionGroups = + contributions.flatMap(contrib => contrib.groups); + + const artistNamesish = + unique( + [artist.name, ...artist.artistAliases.map(alias => alias.name)] + .map(name => getKebabCase(name))); + + const interestingGroups = + unique(contributionGroups) + .filter(group => !artistNamesish.includes(getKebabCase(group.name))); + + if (contributions.length < 50) { + return interestingGroups; + } + + const dividingGroups = + opts.wikiInfo.divideTrackListsByGroups; + + const scores = + new Map(interestingGroups.map(group => [group, 0])); + + for (const group of contributionGroups) { + scores.set(group, scores.get(group) + 1 / contributions.length); + } + + for (const group of interestingGroups) { + if (dividingGroups.includes(group)) continue; + if (scores.get(group) < 0.12) { + scores.delete(group); + } + } + + return Array.from(scores.keys()); +} + function baselineProcess(thing, _opts) { const fields = {}; @@ -173,9 +216,10 @@ function genericProcess(thing, opts) { ]); const groups = - thing.groups ?? - thing.album?.groups ?? - []; + (thing.isAlbum ? thing.groups + : thing.isTrack ? thing.album.groups + : thing.isArtist ? determineArtistGroups(thing, opts) + : []); const mainContributorNames = contributions -- cgit 1.3.0-6-gf8a5