Filter to sort based on the last letter?

How can I sort a Names to make Name.Surname_(SAK3) before Name.Surname_(SAK5) before Name.Surname_(SBK5) …

You can use the :sort[...] filter run prefix to sort a list of input items using a “subfilter” to compute the value to sort by for each input item. The computed value is only used to perform the sort, and :sort[...] returns the original list of input items in the new sorted order.

Something like this:

{{{ [some filter to get names] :sort:string[{!!title}split[_]nth[2]] }}}

-e
1 Like

Thank you but is it Sorten by the last char and then by the secondlast….

ok… try this:

{{{ [some filter to get names] :sort:string[{!!title}split[_]nth[2]split[]reverse[]join[]] }}}

The :sort subfilter:

  • {!!title}split[_]nth[2] gets the “(…)” suffix
  • split[]reverse[]join[] then breaks the suffix into single characters, reverses the order of the characters, and then rejoins them to sort by the reversed text, e.g., (SAK3) becomes )3KAS(

-e

1 Like

Thank you again…it is even trickier: I have to split the content of a field to get the titles.
<$list filter="[{$:/temp/Kursliste}splitregexp[\n]]…???.. :sort:string[{!!title}split[_]nth[2]split[]reverse[]join[]]" variable=each-line>

Could you give us a list of 5 - 10 names and the desired resulting sort order?

Hi @Scott_Sauyet voilà

Name.Surname_(SAK3)
Different.Surnamee_(SAK5)
autre.Nom_(SBK5)

Sorted by the stuff in the brackets in reverse…
As said above devided by \n and pasted into an edit-field

I’m assuming that group is already sorted as you like, correct?

It’s still not clear to me. If we added these, where would they go in the list?

  • autre Nom_(ABC4)
  • autre Nom_(ABC6)
  • Name Surname_(SAK15)
  • Alfred Surname_(SAK3)
  • Alfred Syname_(SAK3)

Alfred Surname_(SAK3)
Alfred Syname_(SAK3)
autre Nom_(ABC4)
autre Nom_(ABD4)
autre Nom_(ABC6)

Name Surname_(SAK15) I guess doublenumbers wont appear.

1 Like
\define setto()
<$action-setfield $tiddler="$:/temp/Kursliste" list=<<fillo>>/>
\end
<$button class="tc-btn-invisible">Generate
<$set name="fillo" filter="[{$:/temp/Kursliste}splitregexp[\n]]">
<<setto>>
</$set>
</$button>

<$list filter="[list[$:/temp/Kursliste]] :sort:string[{!!title}split[_]nth[2]split[]reverse[]join[]]" >

{{!!title}}
</$list>

T
Well this is really tricky, I already came up with strage solutions which did not work :wink:

Not entirely sure if I understood it fully, anyway I give this a try before I’m out of the door:

\function reorder.name( name ) 
[<name>split[_]nth[2]split[]reverse[]join[]] [<name>split[_]butlast[]] +[join[]] 
\end

<$let list=
`
autre Nom_(ABD4)
Alfred Syname_(SAK3)
autre Nom_(ABC6)
autre Nom_(ABC4)
Alfred Surname_(SAK3)
`
>

Original: <br>
<$list filter="[<list>splitregexp[\n]]">
<<currentTiddler>> <br>
</$list>

Interim: <br>
<$list filter="[<list>splitregexp[\n]] :map[function[reorder.name],<currentTiddler>]" >
<<currentTiddler>> <br>
</$list>

Sorted: <br>
<$list filter="[<list>splitregexp[\n]] :sort:string[function[reorder.name],<currentTiddler>]" >
<<currentTiddler>> <br> 
</$list>

Output is:

Original:
autre Nom_(ABD4)
Alfred Syname_(SAK3)
autre Nom_(ABC6)
autre Nom_(ABC4)
Alfred Surname_(SAK3)

Interim:
)4DBA(autre Nom
)3KAS(Alfred Syname
)6CBA(autre Nom
)4CBA(autre Nom
)3KAS(Alfred Surname

Sorted:
Alfred Surname_(SAK3)
Alfred Syname_(SAK3)
autre Nom_(ABC4)
autre Nom_(ABD4)
autre Nom_(ABC6)

This is very clever, and much simpler than anything I had considered.

But I have no idea if it meets the requirements, which are still fairly unclear to me. While I tried to tease them out with examples, I don’t think we ever got enough to demonstrate. But i think we can build a similar solution to more complex requirements just by writing a more sophisticated version of your reorder.name.

Your technique takes the “reverse” quite literally, and so would place Name Surname_(BMX5) before Name Surname_(AMZ5) (because the 5s are the same and XMB comes before ZMA.) I would guess that the opposite is what’s wanted (because the 5s are the same and AMB comes before BMX.) But it is only a guess.

I won’t try to implement the following unless I hear from the OP that it’s right, but this is my guess about what’s desired:

We split the name into four components, A, B, C, and D, so that, for instance, in Autre Nom_(ABC5), we have {A: 'Autre', B: 'Nom', C: 'ABC', D: '5'}.

We sort first on D. Zebediah Zillow_(ZYX3) comes before Annie Applegate_(ABC8) because 3 comes before 8.

Then we sort on C. Zebediah Zillow_(ABC5) comes before Annie Applegate_(XYZ5) because ABC comes before XYZ.

Next is B. Zebediah Applegate_(PDQ4) comes before Annie Zillow_(PDQ4) because Applegate comes before Zillow.

Finally is A. Annie Applegate_(PDQ4 ) comes before Zebediah Applegate_(PDQ4) because Annie comes before Zebediah.

Does that capture it correctly, @JanJo?