I saw references to sorting list results by the count operator but didn’t find the actual threads/posts about the method.
I assume it will require a subfilter, because in a root list filter the count just returns the count of the list results, not counts for each of the list results.
The sortsub operation worked with anything involving the titles of the list results (such as length) but not the count operator.
What I’m aiming for is ranking/sorting results (greatest to lowest counts) of such lists as tags and tiddlers tagged with each or
fields and how many tiddlers have each value of a particular field such as below:
Unless I’m misunderstanding, sortsub[] with a filter containing count[] should do what you need. You might need to add the integer suffix to it though, or else it will sort the numbers alphabetically and not produce a very useful sort.
Where I’m going wrong-- I don’t think a single list/filter (without a subfilter or second filter) will let me sort by the count I’m aiming for, since the count of the root filter would just be the number of different values of the field being filtered, not the count of tiddlers having each different value. Putting in the each[]get[]count[] in the sortsub with any of the suffixes is producing any result.
What I’m starting out with, this gives an alphabetical listing (rather than the default listing without a sort which I assume is by field creation time but not sure if that’s so):
Can you maybe upload a small wiki with some tiddlers that could serve as an example? It’s pretty difficult to go into more depth without any data to try it on.
However, in your enthusiasm I think you over-looked the desire to sort the names by count.
I thought I saw an old post that showed a possible way by using an intermediate list, prefixing the count to the title with a delimiter, sorting the list, and finally splitting the count from the title - but I am unable to find it using search, and also do not recall if the method could be applied in this case.
However, in your enthusiasm I think you over-looked the desire to sort the names by count.
I thought I saw an old post that showed a possible way by using an intermediate list, prefixing the count to the title with a delimiter, sorting the list, and finally splitting the count from the title - but I am unable to find it using search, and also do not recall if the method could be applied in this case.
in TW 5.1.23+ life is much easier! no need to go through that lengthy process! Now you can use the wonderful sortsub!
I made many attempts at a filter but never was able to get it. The missing piece for me is the currentTiddler in the criteria variable. In the context of the list, currentTiddler is the surname. It makes sense after I see it. This indicates I am still not understanding macros and variables correctly.
Soren, sorry about the delay-- this something low on my list of too many things to do, so I haven’t been dedicating enough time to it. Let me export some shell tiddlers with the fields and values from the real world attempt at this issue.
Mohammad, good to see you responding as well. I tried your solution, it displayed the field values with counts but didn’t sort them by the counts (count of fields with each value). Playing with things-- I inserted a <> in the list so that each list result (see [1] beow) would show the criteria variable for each. It’s displaying: [tag[zz@]zztopiccount[]] **(note the " zztopiccount ", zztopic being the field name)
It appears that it’s not applying from the criteria $vars widget. The entire code (yours altered to work with my tiddlers selection) I used is below [2]. It displays what is expect but not sorting.
The code works with data provided by Jim and it also sorts!
To give a try download data of Jim post above and drag and drop to tiddlywiki.com
Next in a new tiddler paste the code of my last post you will see
Thank you Mohammad. I looked at Jim’s tiddlers and your script in TW official and went back and pasted your script into my wiki for another try with the bare minimum of alterations and it worked. I must had typoed during the first attempt. But now I have it working.
Jim, very nice Hobbitology you created, others who create fantasy/ttRPG wikis should look at it. Also, this count script will work great for ranking by stats, achievements, etc-- ie leaderboards.
Soren, thank you and sorry I didn’t get to putting up something for you to work with. But I’m collecting your back links ranking script, along with Mohammad’s field values count ranking and a tagged count ranking I based off them into one thread for Mohammad to add to TWScripts.