This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED] Question on "natural sorting" in Dolphin

Tags: None
(comma "," separated)
User avatar
daihard
Registered Member
Posts
72
Karma
0
OS
Distribution: Kubuntu 10.10
KDE version: 4.5.5

Hi.

I am wondering if someone can educate me on "natural sorting" in Dolphin. It is turned on by default, with which my three files are listed as below.

Code: Select all
pf_bus_2011010203.pdf
receipts_20110405.jpeg
receipts_2011010203.jpeg


My question is, how is it "natural" when "receipts_20110405.jpeg" is listed before "receipts_2011010203.jpeg"? Of course, turning natural sorting off will correctly reverse the order of those two files, but even with natural sorting on, I would expect "receipts_2011010203.jpeg" to be listed before "receipts_20110405.jpeg." Can someone enlighten me on that?

Thanks...

Last edited by daihard on Sun Jun 05, 2011 6:19 pm, edited 1 time in total.


Kubuntu 12.04 (Precise Pangolin) 64-bit / KDE 4.8.1
Work: Dell Precision T5500 (Xeon E5506 @ 2.13 GHz x 2 / 12GB RAM)
Home: Panasonic Toughbook W8 (Core 2 Duo @ 1.20 GHz / 4GB RAM)
User avatar
google01103
Manager
Posts
6668
Karma
25
from the handbook http://docs.kde.org/stable/en/kdebase-a ... lphin.html

Natural sorting of items controls how items are sorted in the view. If this option is enabled, the sort order of three example files will be:
File1,
File2,
File10.

If this option is disabled, the normal alphabetical sorting will be used, which leads to the sort order:
File1,
File10,
File2.

my reading of it is that Dolphin looks at the numbers after "receipts_" and compares their numerical values and as 2011010203 is > 20110405 it is placed last in the sort order


OpenSuse Leap 42.1 x64, Plasma 5.x

User avatar
TheBlackCat
Registered Member
Posts
2945
Karma
8
OS
google is right. Natural sorting, pretty much by definition, treats a series of numerical characters as a single multi-digit number.

So for normal sorting, 100 is treated as a series of three characters, 1, then 0, then 0. For natural sorting, it is treated as a single number, "100".

So when you compare 20 to 100 the standard way, it compares the first characters 1 and 2, and decides the character 2 is larger. That is all it needs to make a decision. With natural sorting, it compares the numbers 20 and 100 and decides the number 100 is larger.

You could think of it as though the number was being treated as a single character with a very large value.


Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965
User avatar
daihard
Registered Member
Posts
72
Karma
0
OS
Aah, I got it. Thanks guys. Since I named those files after the year and month(s) they were related to, it never occurred to me that "2011010203" could be considered a whole number.

With all that in mind, I believe turning natural sorting off will be the better option for me. strcmp() all the way. :)


Kubuntu 12.04 (Precise Pangolin) 64-bit / KDE 4.8.1
Work: Dell Precision T5500 (Xeon E5506 @ 2.13 GHz x 2 / 12GB RAM)
Home: Panasonic Toughbook W8 (Core 2 Duo @ 1.20 GHz / 4GB RAM)
User avatar
TheBlackCat
Registered Member
Posts
2945
Karma
8
OS
If you put dashes in (or some other character) it will sort properly.

So for instance:

pf_bus_2011-01-02-03.pdf
receipts_2011-04-05.jpeg
receipts_2011-01-02-03.jpeg


Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]