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
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
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.
\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
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 5
s are the same and XMB
comes before ZMA
.) I would guess that the opposite is what’s wanted (because the 5
s 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
, andD
, so that, for instance, inAutre Nom_(ABC5)
, we have{A: 'Autre', B: 'Nom', C: 'ABC', D: '5'}
.We sort first on
D
.Zebediah Zillow_(ZYX3)
comes beforeAnnie Applegate_(ABC8)
because3
comes before8
.Then we sort on
C
.Zebediah Zillow_(ABC5)
comes beforeAnnie Applegate_(XYZ5)
becauseABC
comes beforeXYZ
.Next is
B
.Zebediah Applegate_(PDQ4)
comes beforeAnnie Zillow_(PDQ4)
becauseApplegate
comes beforeZillow
.Finally is
A
.Annie Applegate_(PDQ4 )
comes beforeZebediah Applegate_(PDQ4)
becauseAnnie
comes beforeZebediah
.
Does that capture it correctly, @JanJo?