Author Topic: $Sort function unintended result when using with multi-value field  (Read 483 times)

Rumzie

  • Newbie
  • *
  • Posts: 19
Not sure if this is intended, but there seems to be a bug when using the $Sort() function with multi-value fields.

Consider that this function:
$Sort(<Album Artist>)

returns this value:
Dinner Party; Terrace Martin; Robert Glasper; Kamasi Washington

However I was expecting it to return this value:
Dinner Party; Kamasi Washington; Robert Glasper; Terrace Martin

It looks like the sort function sees the multi-value fields as one single string value, and doesn't sort each value alphabetically.
Is there a way I can get the sort function to see each value separately, instead of all the values combined as a single string? Is this a bug, or intended behavior?

Thanks!


Last Edit: April 01, 2025, 01:59:45 AM by Rumzie



Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34972
If you were expecting MB to change the ordering of the names thats not what the $sort function does.
It removes "The" and other words for sorting purposes and applies any custom sort tag you might have entered

karbock

  • Sr. Member
  • ****
  • Posts: 549
@Rumzie:
If you are familiar with mp3tag, v3.29 (released a few days ago) introduces a function that does what you want (sorting the components of a multiple-value tag).

Quote from https://community.mp3tag.de/t/mp3tag-v3-29-released/67991
Quote
Scripting function to sort field contents
When multiple values (e.g., genres, styles, or composers) are stored in a single tag field, sorting them can make similarities more visible — and simply bring some order.
The new scripting function $sort(x,y) sorts segments of a string based on a specified delimiter. It's for example possible to create an action that appends a certain value to existing content and have the combined values sorted automatically. It’s quite handy (though not for everyone).

I've just tested it on a test file, with success, by using this script:
$sort(%artist%,'; ')


hiccup

  • Hero Member
  • *****
  • Posts: 9107
To be honest, when I first read your start post, I found it difficult to understand what you were trying to do exactly.
It looked like you were in fact trying to get the last value of a multi-value tag, so I offered a solution for that.

But now it seems you want to sort the values in a multi-value tag alphabetically.
Why?

And looking at the album I think you are using as an example, the correct Album artist would be:
Dinner Party
Or perhaps:
Dinner Party (Kamasi Washington, Terrace Martin, Robert Glasper & 9th Wonder)

To me it seems you are on a somewhat wrong path here and you should perhaps rethink what you are trying to achieve exactly, and how?

Rumzie

  • Newbie
  • *
  • Posts: 19
Thanks for your replies.

If you were expecting MB to change the ordering of the names thats not what the $sort function does.
It removes "The" and other words for sorting purposes and applies any custom sort tag you might have entered

Correct, I was wrong in assuming this function would sort the multiple values alphabetically.
I might have a look into the new sort feature on Mp3Tag, that looks promising.

But now it seems you want to sort the values in a multi-value tag alphabetically.
Why?

The reason for these (very niche) queries goes back to finding duplicates. I am managing a giant library, and depending on source that files come from, sometimes the album artists are in a different order, so finding duplicates is much easier when you can sort the values alphabetically.
I prefer to have multiple album artists separated into multiple values, especially for programs that create indexes/relationships using this tag (among other tags like performer/composer).
I would prefer to keep the ordering of the album artist tags intact on the files, however I'd like to sort them when I do the actual querying for duplicates.
Last Edit: April 01, 2025, 10:10:07 PM by Rumzie

hiccup

  • Hero Member
  • *****
  • Posts: 9107
I would prefer to keep the ordering of the album artist tags intact on the files, however I'd like to sort them when I do the actual querying for duplicates.
I think things would be much easier and properly handled if you would use Album Artist as a single value tag, populating it with the album artist name as printed on the album cover and websites such as MusicBrainz and Discogs.
And in addition use a separate Album Artists tag for your multi-value purposes.

But maybe that won't work for you if you are also using other software or players for other purposes?

PS
Perhaps you could put out a request for boroda's AT&RT plugin to have some $SortMulti function to alphabetically sort multi-value tags?
I think it wouldn't serve a purpose for most users, but for some specific niche user cases it might be useful to have available.
Last Edit: April 02, 2025, 09:00:04 AM by hiccup

Rumzie

  • Newbie
  • *
  • Posts: 19
I would prefer to keep the ordering of the album artist tags intact on the files, however I'd like to sort them when I do the actual querying for duplicates.
I think things would be much easier and properly handled if you would use Album Artist as a single value tag, populating it with the album artist name as printed on the album cover and websites such as MusicBrainz and Discogs.
And in addition use a separate Album Artists tag for your multi-value purposes.

But maybe that won't work for you if you are also using other software or players for other purposes?

PS
Perhaps you could put out a request for boroda's AT&RT plugin to have some $SortMulti function to alphabetically sort multi-value tags?
I think it wouldn't serve a purpose for most users, but for some specific niche user cases it might be useful to have available.

I honestly haven't run into any programs that use the "Album Artists" tag before, but that does seem like a potentially ideal solution. Sadly I don't see myself going back to edit thousands of albums.
Using combined values in the Album Artist tag just doesn't make sense to me honestly, especially for indexing/organizational purposes. Maybe for a group it does (like Dinner Party), but not so much for classical or collaboration albums.

Is there a specific thread I should post in for a request to have a $SortMulti function added? Not sure this falls under the Additional Tagging section but I could be wrong.

Thanks!!!

hiccup

  • Hero Member
  • *****
  • Posts: 9107
I honestly haven't run into any programs that use the "Album Artists" tag before, but that does seem like a potentially ideal solution. Sadly I don't see myself going back to edit thousands of albums.
Regrettably Album Artists is not a common tag, and even for MusicBee you will have to create a custom tag for it before you can use it.
So you have thousands of albums that can be considered to have multiple album artists?
That's a lot!

Quote
Using combined values in the Album Artist tag just doesn't make sense to me honestly,...
Neither does it to me.
The 'album artist' for an album is usually artist intent, and should be respected in my opinion.
For example:
  Eno & Hyde
  Corea, Clarke & White
  Rufus With Chaka Khan
  Chet Baker Quartet Featuring Russ Freeman

If these individual artists were split up in a multi-value tag, how would one know anymore what the correct and original album artist for that album is?

Quote
Is there a specific thread I should post in for a request to have a $SortMulti function added? Not sure this falls under the Additional Tagging section but I could be wrong
Just post in the plugin's thread.
Boroda will see it there sooner or later.
Make sure to explain the purpose and/or paste a link to your post in this thread about it.
Last Edit: April 02, 2025, 10:13:27 PM by hiccup