Bug Album List - Odd Sort Behaviour
#1
Bug 
Firstly apologies if this has been covered elsewhere, I did try searching but it's not a particularly easy thing to search so I could well have missed the information.

I running Kodi 16.1 on a Raspberry Pi 2 on OSMC with a pretty vanilla configuration.

I have a lot of music on an external USB drive which I have added as a source and imported to Kodi.

The odd behaviour (at least it seems odd to me) is that in Music>Library>Albums, where I have multiple compilation albums from the same series the numbered releases, i.e. from 2 onwards, appear in the list before the original release. That's kind of hard to explain so here's a couple of examples:

Absolute Hardcore 2
Absolute Hardcore

Back To The Old Skool 2
Back To The Old Skool Drum N Bass
Back To The Old Skool

What I would expect to see is:

Absolute Hardcore
Absolute Hardcore 2

Back To The Old Skool
Back To The Old Skool 2
Back To The Old Skool Drum N Bass

My view options are:

View:List
Sort by:Album
Sort:Ascending

Strangely if I change this to:

View:List
Sort by:Artist
Sort:Ascending

It appears the secondary sort of album name works as expected, so I see the following:

Back To The Old Skool / Various Artists
Back To The Old Skool 2 / Various Artists
Back To The Old Skool Drum N Bass / Various Artists

I don't know if this is a bug, something wrong with my set up or if I'm just missing a fundamental understanding of how the sort works but if anyone can shed any light on this it would be appreciated.

Thanks
Reply
#2
Sounds odd. I have had some similar strange behavior when the names contained " / ", but not just numbers. I'll have a look when I get back after the weekend. I suspect it is the strutils::AlphaNumericCompare giving an undefined order.
Reply
#3
Thanks for the quick reply will look forward to seeing if you can track the issue down Smile
Reply
#4
Well I can repeat the odd sort behaviour you are seeing, so it is Kodi bug not a set up issue.

Whether I can fix it without breaking sorting even more is another question. While alphanumeric sorting of text looks deceptively simple, and something that should have been solved multiple times by many projects to produce standrd algorithms, in reality it is harder. Differing language standards and treatment of accents etc. to consider.

But I think it is terribly sad if Kodi can't get some kind of consistent results in even one language, so I will have a go.

Edit:
Turns out StringUtils::AlphaNumericCompare was innocent Smile
It is all down to the way that Kodi applies multiple field sorting by concatenating the fields into a single string and sorting that. That is a fatally flawed approach Sad

When sorting albums by artist (and implicitly album title) it sorts using string <artist name> <album title>.
In your example that gives

"Various Artists Back To The Old Skool"
"Various Artists Back To The Old Skool 2"
"Various Artists Back To The Old Skool Drum N Bass"

When sorting by album title (and implicitly artist) it sorts using string <album title> <artist name>.
In your example that gives

"Back To The Old Skool 2 Various Artists"
"Back To The Old Skool Drum N Bass Various Artists"
"Back To The Old Skool Various Artists"

Multiple field sorting need the fields to considered separately, not attempted by concatening to a single string.

This sorting issue is wider than just albums, it possibly impacts video library as well.
Reply
#5
Thanks for that. I've had some interest as users complained about bad collation for their language, which I guess is implemented in AlphaNumericCompare. I can see this implementation is broken.

scott s.
.
maintainer of skin  Aeon MQ5 mods for post-Gotham Kodi releases:
Matrix see: Aeon MQ5 Mod Martix release thread
Leia see: Aeon MQ5 Mod Leia release thread
Reply
#6
Apologies for bumping this old thread but I somehow missed the replies at the time and since posting have upgraded to version 17 and the same issue is still present (although I'm not implying there was any suggestion that it would be fixed in version 17)

Is there any work underway to resolve the issue? It sounds like it's a lot more complicated than I imagined it would be!

I've since found another sorting issue which may or may not be related and may or may not not deserve its own thread.

I've noticed that letters with an accent are sorted to the end of the alphabet. I have very examples in my library which is probably why I've not noticed it before but the example I've found was for the artist Shèna.

Now my preference would be that the sort would ignore the accent and treat is as the normal letter "e" which in my library would have it sorting like so:

Shed Seven
Shèna
Shere Khan

However it is sorted to the end of the artists starting with Sh*, i.e.

Shy FX & T Power
Shèna
Siamese

I thought I had recalled reading a way of configuring the behaviour that I'm after but I can't find it now. Is there anything that I can do in situ to get the sorting I want or is it something I will have to live with (it's only a very minor issue to be fair)
Reply
#7
(2017-03-04, 23:31)Hallucyn8 Wrote: Is there any work underway to resolve the issue? It sounds like it's a lot more complicated than I imagined it would be!
Yes and yes Smile
I am still debating how much sorting at the db we can do. At the moment all sorting is done within local memory in Kodi, but it would be quicker at the db. It is stuff for v18, so last minute v17 fixes have been taking priority, but sorting is on my work list.

Quote:I've since found another sorting issue which may or may not be related and may or may not not deserve its own thread.

I've noticed that letters with an accent are sorted to the end of the alphabet. I have very examples in my library which is probably why I've not noticed it before but the example I've found was for the artist Shèna....
Fine here, it is relevent.

Kodi uses std::collate taking your current locale as a parameter to do its alphanumeric sorting i.e. it will treat accent characters differently depending on what country you have set as your location in regional settings. But I am unclear if there is a locale that will give you the sort that you want. I'm pretty sure they all treat "è" as a different char to "e", while what you want is something that simpifies unicode into "A to z" ascii.

As it happens this collation is something that makes sorting in the db a little harder (SQLite can do it, but not so sure about MySQL yet). But there may be a better way around it also comming in v18 - use of ARTISTSORT tag. For every artist we can store a sort name, my initial motivation is so that "Shere Khan" with sort name = "Khan, Shere" could come up under K not S, but it could also be use for accents e.g. "Shèna" can have sort name "Shena".

I already have a PR in for processing ARTISTSORT etc. tags, but unfortunately no one on the team has had time or interest to review it yet. It means a db change, so my other work that entails db changes is stuck in a queue in my repo. The frustrations of being a solo dev with interest in music!
Reply
#8
Thanks for the update, detailed and informative as ever Smile
Reply
#9
Isn't it the case that std::locale gets the actual collate facet sequence from the system it is running on? So if that's correct users need to look at their platform/OS documentation to see how it is implemented. Meanwhile in the SQLite I think it is using binary collation so for example Latin upper case letters (Z) sort before lower case (a).
My interest is more in search/filter than sorting though.

scott s.
.
maintainer of skin  Aeon MQ5 mods for post-Gotham Kodi releases:
Matrix see: Aeon MQ5 Mod Martix release thread
Leia see: Aeon MQ5 Mod Leia release thread
Reply
#10
Yes Scott by default SQLite uses ascii sort order, but Kodi currently does not use SQL ordering at all.

The collate facet seems to look at Kodi settings, but I guess the patform may have some effect on implementation too, I really don't know.
Reply



Logout Mark Read Team Forum Stats Members Help
Album List - Odd Sort Behaviour0
This forum uses Lukasz Tkacz MyBB addons.