[TW5] Unexpected behaviour of filter/sort

149 views
Skip to first unread message

Richard Evans

unread,
Jan 18, 2016, 3:21:31 AM1/18/16
to TiddlyWiki
Hi,

I have been exploring the filter mechanism in TW5. First I am surprised to find it classified as a Concept, rather than as a Widget, but as I have said before the logic of the TiddlyWiki language escapes me.

If I use the following code:-

<ul><$list filter="[tag[Use Case]]" sort="title">
<li>
<$link><
<currentTiddler>></$link>
</li>
</$list>
</ul>

On the tiddlers entitled as follows, 1.0 Use Case, 2.0 Use Case, 2.1 Use Case, Add Case, Subtract Case, Multiply Case I get the following result:-

  • Add Case
  • Multiply Case
  • Subtract Case
  • 2.1 Use Case
  • 2.0 Use Case
  • 1.0 Use Case

Which is not what I expected, most sorts, sort the numbers in ascending order and before the Alphabetic characters.


Is there some default I have to change?


Am I alone in thinking that a filter is different from a sort? Making sort subsiduary to filter seems illogical to me.


          Regards   Ric Evans




Eric Shulman

unread,
Jan 18, 2016, 4:25:36 AM1/18/16
to TiddlyWiki
On Monday, January 18, 2016 at 12:21:31 AM UTC-8, Richard Evans wrote:
I have been exploring the filter mechanism in TW5. First I am surprised to find it classified as a Concept, rather than as a Widget, but as I have said before the logic of the TiddlyWiki language escapes me.

Filters can be used as parameter values for several different types of Widgets, including $list, $set, various $action-* widgets, etc.  They can also be used in some special cases, such as entering a filter expression into $:/DefaultTiddlers to automatically compute which tiddlers are to be shown at startup (e.g., put [tag[startup]] in $:/DefaultTiddlers, and then just add the "startup" tag to any tiddlers you want displayed).
 
If I use the following code:-

<ul><$list filter="[tag[Use Case]]" sort="title">
<li>
<$link><
<currentTiddler>></$link>
</li>
</$list>
</ul>

The documentation for the <$list> widget does not include mention of a sort="..." parameter, so I don't think any sorting actually occurred.  Rather, I think you are just seeing the "natural" order (based on creation) of the tagged tiddlers.  To actually sort the filter output, you should use the [sort[]] filter operator, like this:
<$list filter="[tag[Use Case]sort[title]]">
 

Am I alone in thinking that a filter is different from a sort? Making sort subsiduary to filter seems illogical to me.


Filter operators work by modifying the current "input set" in various ways... adding, removing or changing the order of the items in the set.  By default, the input set starts with all 'real' tiddlers (excluding shadow tiddlers).  The [tag[...]] operator then selects only those tiddlers with the indicated tag value.  The [sort[...]] operator then alters the order of the set of tiddlers.

Sorting a set can be integral to the logic of filtering.  For example, suppose I want to list, in alphabetical order, the ten most recent tiddlers tagged with "task".  To achieve this, the filter expression would be:
[tag[task]!sort[modified]limit[10]sort[title]]

Note also that the [sort[...]] operator uses a standard character-based sort, so numbers are treated as simple strings of characters, rather than numeric values.  To sort by *numeric value*, use the [nsort[...]] operator instead.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
InsideTiddlyWiki: The Missing Manuals


Richard Evans

unread,
Jan 18, 2016, 5:31:58 PM1/18/16
to TiddlyWiki
On Monday, January 18, 2016 at 9:25:36 AM UTC, Eric Shulman wrote:
On Monday, January 18, 2016 at 12:21:31 AM UTC-8, Richard Evans wrote:
I have been exploring the filter mechanism in TW5. First I am surprised to find it classified as a Concept, rather than as a Widget, but as I have said before the logic of the TiddlyWiki language escapes me.

Filters can be used as parameter values for several different types of Widgets, including $list, $set, various $action-* widgets, etc.  They can also be used in some special cases, such as entering a filter expression into $:/DefaultTiddlers to automatically compute which tiddlers are to be shown at startup (e.g., put [tag[startup]] in $:/DefaultTiddlers, and then just add the "startup" tag to any tiddlers you want displayed).

Thank you interesting information, but not exactly germain to my question.
 
If I use the following code:-

<ul><$list filter="[tag[Use Case]]" sort="title">
<li>
<$link><
<currentTiddler>></$link>
</li>
</$list>
</ul>

A very strange thing has happened, when I was editting my file yesterday, I was getting the result I described, but today when I opened the file, my results had changed to:-

  • 1.0 Use Case
  • 2.0 Use Case
  • 2.1 Use Case
  • 2.1.1 Use Case
  • Add Case
  • Multiply Case
  • Subtract Case

    Which is the expected behaviour. It would seem TiddlyWiki has bugs.

     
    The documentation for the <$list> widget does not include mention of a sort="..." parameter,

    No <$list> does not mention of a sort parameter,  but 
    <$list filter="[tag[Use Case]]" sort="title">

    works try changing title for 'created' or some other sort operation.  Even though it is not documented it seems to work. Your suggestion of
    <$list filter="[tag[Use Case]sort[title]]">
    does exactly the same thing in my limited testing.


    so I don't think any sorting actually occurred.  Rather, I think you are just seeing the "natural" order (based on creation) of the tagged tiddlers.  To actually sort the filter output, you should use the [sort[]] filter operator, like this:
    <$list filter="[tag[Use Case]sort[title]]">
     
    The original point I was making is that the order produced was un-natural from my point of view, putting numbers after characters.

    Am I alone in thinking that a filter is different from a sort? Making sort subsiduary to filter seems illogical to me.


    Filter operators work by modifying the current "input set" in various ways... adding, removing or changing the order of the items in the set.  By default, the input set starts with all 'real' tiddlers (excluding shadow tiddlers).  The [tag[...]] operator then selects only those tiddlers with the indicated tag value.  The [sort[...]] operator then alters the order of the set of tiddlers.

    Sorting a set can be integral to the logic of filtering.  For example, suppose I want to list, in alphabetical order, the ten most recent tiddlers tagged with "task".  To achieve this, the filter expression would be:
    [tag[task]!sort[modified]limit[10]sort[title]]

    This is an argument for re-using code not for subsuming the sort operation into filter.

    Tobias Beer

    unread,
    Jan 18, 2016, 6:32:28 PM1/18/16
    to TiddlyWiki
    Hi Richard,
     
    Thank you interesting information, but not exactly germain to my question.

    Eric's answer was spot-on, very much germane indeed.
    I actually stored it as a reference.

    It would seem TiddlyWiki has bugs.


    There may be those, but your case ain't one of them. ;-)

    No <$list> does not mention of a sort parameter,  but 
    <$list filter="[tag[Use Case]]" sort="title">

    works try changing title for 'created' or some other sort operation.
    Even though it is not documented it seems to work.  

    It does not work, neither is it documented, nor is it part of the core list widget code.
    You can easily verify this on TiddlyWiki.com by creating a tiddler containing:

    <table><tr><td>

    <$list sort="title"/>

    </td><td>

    <$list sort="modified"/>

    </td></tr></table>

    So...
     
    Your suggestion of
    <$list filter="[tag[Use Case]sort[title]]">
    does exactly the same thing in my limited testing.

    Eric's suggestion works as designed and
    does not at all do the same thing as what you tried.

    The original point I was making is that the order produced was un-natural from my point of view, putting numbers after characters.

    This is because your example did not do any sorting in the first place. 

    Am I alone in thinking that a filter is different from a sort? 

    Making sort subsiduary to filter seems illogical to me.


    You are free to feel this way about this design choice.
    But then again, you appear to be the first one to be irritated by it.
    Sorting is a filter operation in TiddlyWiki for quite practical reasons.

    This is an argument for re-using code not for subsuming the sort operation into filter.

    Efficiency is an important issue.
    Sure, you may not have seen a model where sorting is designed as a subset of filtering.
    But then, there are a lot of things yet unseen by someone.
    Does that mean that those things should not be what they are?

    Best wishes,

    Tobias.
    Reply all
    Reply to author
    Forward
    0 new messages