+2
Under review

Natural Sorting for Title

Chris Moore 10 years ago updated by Alex Jenter 10 years ago 13
CN does not yet have an option for natural sorting for numbers in the title field. eg
Note 1
Note 2
Note 10

CN will sort these like so:
Note 1
Note 10
Note 2

Natural sorting would be:
Note 1
Note 2
Note 10

Windows itself defaults to natural sorting now, and I think CN should as well.
viewing notes-list sorting
Under review
Thanks for the suggestion, Chris! Do you think this should be an option, or that CN should just silently switch to natural sorting for titles?
It's not really Windows ;) I've checked the samples with Explorer and Total Commander. The latter does not support "natural" sorting, whereas Explorer does. That came as a surprise to me. I was not aware of this. Since it probably will affect only titles which are organized in a way, such as represented in the samples, i think it will be ok, to switch to natural sorting as the default.
I missed a word - I meant "Windows Explorer", not "Windows" :)

(But as you have discovered below, TC does indeed support natural sorting and has done for a number of years)
Curious as i am, i checked Total Commanders Settings. Guess what? It does support options, which allow to support for natural sorting. It even has multiple settings for it. As for "natural" sorting it can even distinguish for accents and German Umlauts, which requires a function of Internet Explorer (as the help notes).
Chris, thanks for bringing this up. One just can not stop learning. ;)
I think there's a reason why this is an option: "natural" sorting requires extra processing and is slower than the default sorting. If you don't need natural sorting, why should you pay with performance for it?
That's what i think too. Natural sorting does require computing, which can slow down ordering dramatically. The only exception i can think of, is building an appropriate index which uses a user defined function on the title field. I did not check though, whether SQLite does support user defined functions. Unless this can be done right, it is probably best to leave sorting the way it is. A workaround i use in these cases is "Note 01", "Note 02", etc.
SQLite does support user-defined functions, but it seems that SQLite doesn't support functional indices. However it does support custom collations, and this is what should be used here. Still I think it will be much slower than the Unicode  collation that is used now.

So let's wait till this suggestion gets some votes first :)
Yes, I intended it to be an option that the user could enable if they wished. I know there are people out there that don't like natural sorting - there were some very vocal opponents of the option when it was added to Total Commander for example, and I am sure that some of those use CN as well - but I like natural sorting very much and would accept the potential downside of decreased performance.
To avoid extra work in the UI and also to avoid user disagreement it's probably best to introduce natural sorting as an ini setting controlling sorting of the title.
Agreed. And implementation will use a custom collation. Hopefully we'll even be able to find a ready-made implementation of the natural order sort function.
But first we need to see some votes, of course ;)
I did a quick search on google. Here are some interesting results:

• StrCmpLogicalW function
- min XP
- Unicode only
http://msdn.microsoft.com/en-us/library/bb759947(VS.85).aspx

• Sorting for Humans : Natural Sort Order
http://blog.codinghorror.com/sorting-for-humans-natural-sort-order/

• WHAT IS UP WITH NUMBER SORTING?
http://www.siao2.com/2005/01/05/346933.aspx

• Windows Numerical Sort: Why Numeric File Names are Sorted Differently
http://www.meridiandiscovery.com/how-to/why-windows-sorts-numeric-file-names-differently/

This requires in memory sorting, which heavily influences performance. I did not find an easy solution which would support SQLite.
Thomas, thanks for the links, will certainly come in handy!