Tinderbox Forum

Force sorting to respect numeric order?

I have a user attribute used to sort my notes. The numbering system is alphanumeric, which means the attribute type is ‘string’, and precludes the use of ‘number’.

The problem is that when sorting, it results in an order 0_1, 0_10, 0_2; where 10 comes between 1 and 2. Unfortunately switching over to a pure numeric system won’t work.

Is there any way to force the sorting of notes to respect the numeric order even when the attribute is set to ‘string’?

To mix lexical and numerical sorts in the same sort? I believe not. An .nsort() can force numerical sort on a non-number/mixed list.

If I understand you correctly, you have a string attribute with numerical characteristics. Like

630.87 Dela42
630.9 Aber47

Tinderbox sorts these lexicophraphically, but you’d like to sort them numerically.

What I’d suggest is that you extract the numeric portion of your name, and store it in a numeric user attribute. Sort on the numeric attribute, but display the string attribute. That should do what you want!

1 Like

Thank you both for the quick help. @eastgate: yes, it is as you understood correctly — I am using a string attribute. Unfortunately I do not think your solution works in my case.

To make it easier to explain, let us assume that I am trying to sort by $Name. And let us assume that my notes have names like 0_2a14, 0_10,3a, and 0_10,20b.

At the moment, these three are being sorted:


MarkB: to my mind, there is no way I can extract the numeric portion of the name. This is because the naming pattern itself is very extensible, and may contain numbers after letters, and further letters after those numbers, ad infinitum.

At the moment, 0_10,3a is being sorted before 0_2a14. And 0_10,20b is being sorted before 0_10,3a.

@mwra Unfortunately I haven’t been able to figure out how to get your suggestion to work. But it is as you say: I want to force a numerical sort on a non-number/mixed list like the above.

Sorry, I should make plain that you can’t apply .sort() directly to a container - i.e. sorting the view.

In your names, are the ‘a’ and ‘b’ hexadecimal numbers or a literal letter, i.e. a lowercase ‘A’, etc.?

It’s hard to understand the syntax here, in order to break it into one (or more) attributes to use for sorting as per @eastgate’s suggestion above. For instance 0_10,20b seems to split to 4 parts 0/10/20/b but 0_2a14 gives 0/2/a/14/. Mixing the two I get N/N{1,2}/A/N{1,2}/A when N are numbers and A letters. Is there some underlying logic to the naming convention?

They are literal letters, i.e. a lower case ‘a’, ‘b’, etc.

I don’t think they can be broken down into separate attributes. The logic of the naming convention:

  • If I have a note and wish to add another note which serves as an addendum, I go to the next letter. So 0_10,20b is followed by 0_10,20c.
  • Each time I create a new note which branches off an existing note, I add a letter or number. These alternate. So 0_10,3a could have a branch named 0_10,3a1.
  • If I later wish to slip a new note in between two existing notes, I would use a comma and another number or letter. So if I presently have 0_2a14 and 0_2a15, but then wish to make an addendum, I would get 0_2a14,1.

In there words, there is a logic, but it does not lend it self to breaking down it down into simple patterns of numbers and letters.

@talazem : in this case, what you must do is to extract each subfield into a separate numeric attribute — converting letters or letter sequences to a corresponding numeric value. It’s a nuisance, but it’s not our fault — it is Prof. Luhman’s!

“Respecting numeric order” in your case isn’t sufficient.

1 Like

You’ve clearly done your compulsory Luhmann homework, @eastgate.

If I understand correctly, then, sorting such a style of ‘numbering’ cannot be done due to its unpredictable nature. There is no pattern. And to convert all the letters into separate numeric values is something I cannot even imagine how to do, while still using Luhamnn’s numbering system.

Interestingly, when I export the notes into Finder, the Finder sorts them all ‘correctly’. But I am only doing this for long-term backup, so to speak. It doesn’t help me with using my TBX based note collection according to Luhmann’s numbering principles.

This simply means I cannot use ‘sort’, and will just have to manually sort my notes (and keep good backups incase something goes awry). Many thanks to you both, anyhow.

1 Like

Oh – this CAN be done! I expect that you can sort this system, right? And you could teach a graduate assistant to do it. So can Tinderbox. But it’s going to be a bit tricky, because the hybridity makes it harder.

I believe you’ll find that Finder sorts incorrectly as you get to more complex cases.

If this matters, and if you can describe what sort order you need, Tinderbox can do it. But as you say, it may be better to do this manually. That’s what Luhmann did, after all.

(Converting letters to numbers: use a lookup table. It’s not hard. But again, manual sorting may be good enough.)

Interesting. Good, I’ll look into using a lookup table.

The main reason for wanting to be able to sort automatically is in case of a mistake in which my manual sorting goes all wrong somehow. For example, if I accidentally run some other form of sorting, my manual sorting would be destroyed — a digital version of a windstorm throwing open my slip box and casting notes all over my office! Having already invested time into organising the notes into note-sequences, I wanted to ensure they could be sorted quickly if something went wrong.

1 Like

Here’s another approach:

  1. Begin with a simple numeric system: 1,2,3,4,5…
  2. Need to interpolate a slip between 1 and 2? Call it 1;1. The next one is 1;2
  3. Need to interpolate a slip between 1 and 1.1? It’s 1;0;1

This isn I think, almost exactly what Luhmann did. We’re just (a) using numbers throughout, and (b) using semicolons instead of periods?

Why semicolons? Because then we map directly onto Tinderbox lists. And it’s easy to convert a list into a string with periods instead of semicolons for display.

So I’ve gotten a basic lookup table working.

But, with apologies, @eastgate, I’m still not clear how to use it to convert something like “10,3a” to something that can be sorted for display, as you mentioned. How do we just target certain numbers or letters (say, ‘10’ or ‘a’ in my example) within a longer string?

(If this is getting too baroque, we can abandon the experiment. And either I’ll stick to manual sorting or figure out another equally extensible numbering system that allows for note-sequences, aka folgezettel.)

1 Like

You’ll need to extract the components

10.3.a ➛ 10 ; 3 ;a

Then, map this into a number

 10 * 100*100   + 3 * 100  + 1

where the final 1 is the lookup value for ‘a’. This gives you a big number you can sort on.

1 Like

Thank you, Mark. I think I’ll stick to manual sorting. I’ll continue to write the Luhmann-style numbering into an attribute — not for the purpose of sorting, but in order to maintain the same structure of the note collection when exporting into text files.

I got my head around a basic lookup table, but can’t figure out how one would ‘extract the components’ or to ‘map this into a number’ (and an honest go through TBRef didn’t throw anything up). While I’d be happy to learn how to do both steps above in order to add to my TBX skills, I don’t wish to take any more of the developer’s time. Especially when a low-tech approach of manual sorting will probably be just fine.

An update (for those who might be interested in creating a zettelkasten in Tinderbox): I have settled on using the System Attribute ‘OutlineOrder’.

I have written out the reasoning in another thread in case it is of help to others, and to elicit feedback if there is a better way.