diff options
Diffstat (limited to 'src/common-util')
| -rw-r--r-- | src/common-util/search-shape.js | 7 | ||||
| -rw-r--r-- | src/common-util/sort.js | 80 | ||||
| -rw-r--r-- | src/common-util/wiki-data.js | 13 |
3 files changed, 73 insertions, 27 deletions
diff --git a/src/common-util/search-shape.js b/src/common-util/search-shape.js index 3f1d9ed2..d0db3ea2 100644 --- a/src/common-util/search-shape.js +++ b/src/common-util/search-shape.js @@ -8,6 +8,7 @@ const baselineStore = [ 'primaryName', + 'nameDetail', 'disambiguators', 'classification', 'artwork', @@ -20,10 +21,9 @@ const searchShape = { generic: { index: [ 'primaryName', + 'nameDetail', 'parentName', - 'artTags', 'additionalNames', - 'contributors', 'groups', ].map(field => ({field, tokenize: 'forward'})), @@ -33,10 +33,9 @@ const searchShape = { verbatim: { index: [ 'primaryName', + 'nameDetail', 'parentName', - 'artTags', 'additionalNames', - 'contributors', 'groups', ], diff --git a/src/common-util/sort.js b/src/common-util/sort.js index b87ef500..26363ac3 100644 --- a/src/common-util/sort.js +++ b/src/common-util/sort.js @@ -40,11 +40,15 @@ export function normalizeName(s) { // punctuation, with a single typical space, then trim the ends. s = s .replace( - /[\p{Separator}\p{Dash_Punctuation}\p{Connector_Punctuation}]+/gu, + /[/\p{Separator}\p{Dash_Punctuation}\p{Connector_Punctuation}]+/gu, ' ' ) .trim(); + // Zero-prefix sequences of digits (bounded by only select characters), + // so lesser-value numbers precede greater. + s = s.replace(/(?<=[ ({\[<]|^)\d+(?=[ )}\]>]|$)/g, match => match.padStart(5, '0')); + // Discard anything that isn't a letter, number, space, or apostrophe. s = s.replace(/[^\p{Letter}\p{Number} ']/gu, '').trim(); @@ -86,9 +90,10 @@ export function normalizeName(s) { // sortByDirectory will handle the rest, given all directories are unique // except when album and track directories overlap with each other. export function sortByDirectory(data, { - getDirectory = object => object.directory, + getDirectory = nativeGetDirectory, } = {}) { - const directories = data.map(getDirectory); + const directories = + data.map(thing => getDirectory(thing, nativeGetDirectory)); sortMultipleArrays(data, directories, (a, b, directoryA, directoryB) => @@ -97,11 +102,18 @@ export function sortByDirectory(data, { return data; } +export function nativeGetDirectory(thing, _nativeGetDirectory) { + return thing.directory; +} + export function sortByName(data, { - getName = object => object.name, + getName = nativeGetName, } = {}) { - const names = data.map(getName); - const normalizedNames = names.map(normalizeName); + const names = + data.map(thing => getName(thing, nativeGetName)); + + const normalizedNames = + names.map(normalizeName); sortMultipleArrays(data, normalizedNames, names, ( @@ -117,6 +129,13 @@ export function sortByName(data, { return data; } +export function nativeGetName(thing, _nativeGetName) { + return ( + thing.nameForSorting ?? + thing.name + ); +} + export function compareNormalizedNames( normalizedA, normalizedB, nonNormalizedA, nonNormalizedB, @@ -129,10 +148,11 @@ export function compareNormalizedNames( } export function sortByDate(data, { - getDate = object => object.date, + getDate = nativeGetDate, latestFirst = false, } = {}) { - const dates = data.map(getDate); + const dates = + data.map(thing => getDate(thing, nativeGetDate)); sortMultipleArrays(data, dates, (a, b, dateA, dateB) => @@ -141,6 +161,10 @@ export function sortByDate(data, { return data; } +export function nativeGetDate(thing) { + return thing.date; +} + export function compareDates(a, b, { latestFirst = false, } = {}) { @@ -283,8 +307,8 @@ export function sortByConditions(data, conditions) { // * directory (or override getDirectory) // * name (or override getName) export function sortAlphabetically(data, { - getDirectory, - getName, + getDirectory = undefined, + getName = undefined, } = {}) { sortByDirectory(data, {getDirectory}); sortByName(data, {getName}); @@ -297,9 +321,9 @@ export function sortAlphabetically(data, { // * date (or override getDate) export function sortChronologically(data, { latestFirst = false, - getDirectory, - getName, - getDate, + getDirectory = undefined, + getName = undefined, + getDate = undefined, } = {}) { sortAlphabetically(data, {getDirectory, getName}); sortByDate(data, {latestFirst, getDate}); @@ -369,16 +393,23 @@ export function prepareAndSort(sources, prepareForSort, sortFunction) { // // This function also works for data lists which contain only tracks. export function sortAlbumsTracksChronologically(data, { + getDate = undefined, latestFirst = false, - getDate, } = {}) { // Sort albums before tracks... sortByConditions(data, [t => t.isAlbum]); // Put albums alphabetically, and group with them... sortAlphabetically(data, { - getDirectory: t => t.isTrack ? t.album.directory : t.directory, - getName: t => t.isTrack ? t.album.name : t.name, + getDirectory: (thing, nativeGetDirectory) => + (thing.isTrack + ? nativeGetDirectory(thing.album) + : nativeGetDirectory(thing)), + + getName: (thing, nativeGetName) => + (thing.isTrack + ? nativeGetName(thing.album) + : nativeGetName(thing)), }); // Sort tracks by position in album... @@ -410,13 +441,16 @@ export function sortArtworksChronologically(data, { } export function sortFlashesChronologically(data, { + getDate = undefined, latestFirst = false, - getDate, } = {}) { // Group flashes by act... sortAlphabetically(data, { - getName: flash => flash.act.name, - getDirectory: flash => flash.act.directory, + getName: (flash, nativeGetName) => + nativeGetName(flash.act), + + getDirectory: (flash, nativeGetDirectory) => + nativeGetDirectory(flash.act), }); // Sort flashes by position in act... @@ -432,8 +466,8 @@ export function sortFlashesChronologically(data, { } export function sortContributionsChronologically(data, sortThings, { + getThing = nativeGetContributionThing, latestFirst = false, - getThing = contrib => contrib.thing, } = {}) { // Contributions only have one date property (which is provided when // the contribution is created). They're sorted by this most primarily, @@ -442,7 +476,7 @@ export function sortContributionsChronologically(data, sortThings, { const entries = data.map(contrib => ({ entry: contrib, - thing: getThing(contrib), + thing: getThing(contrib, nativeGetContributionThing), })); sortEntryThingPairs( @@ -463,3 +497,7 @@ export function sortContributionsChronologically(data, sortThings, { return data; } + +export function nativeGetContributionThing(contrib, _nativeGetContributionThing) { + return contrib.thing; +} diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js index f47a48ff..d407cb4e 100644 --- a/src/common-util/wiki-data.js +++ b/src/common-util/wiki-data.js @@ -177,7 +177,7 @@ export function filterAlbumsByCommentary(albums) { export function getAlbumCover(album, {to}) { // Some albums don't have art! This function returns null in that case. if (album.hasCoverArt) { - return to('media.albumCover', album.directory, album.coverArtFileExtension); + return to(...album.coverArtworks[0].path); } else { return null; } @@ -235,6 +235,15 @@ export function getArtistNumContributions(artist) { artist.flashContributorContributions .filter(keep), + + artist.miscellaneousAdditionalFileArtistContributions + .filter(keep), + + artist.sheetMusicFileArtistContributions + .filter(keep), + + artist.midiProjectFileArtistContributions + .filter(keep), ], ({length}) => length); } @@ -265,7 +274,7 @@ export function getTrackCover(track, {to}) { if (!track.hasUniqueCoverArt) { return getAlbumCover(track.album, {to}); } else { - return to('media.trackCover', track.album.directory, track.directory, track.coverArtFileExtension); + return to(...track.trackArtworks[0].path); } } |