Just a Filtering Code Pattern

91 views
Skip to first unread message

Charlie Veniot

unread,
Sep 23, 2021, 9:54:34 PMSep 23
to TiddlyWiki
Me and my interest in brain age games, I couldn't help but play around with a filter to find all tiddlers that have all four specified tags, but only those four tags.

You'll find three tiddlers in the attached json.  Download the file, and drag into some TiddlyWiki instance (TiddlyWiki.com !) to take a gander.

There are all kinds of ways to go about doing this sort of thing, with some filter operators maybe better suited, but I find the result a bit easier for me to understand (more logical to me, or maybe more self-explanatory, because of the way my brain works, I suppose.)  Maybe just a difference between top-down view vs bottom-up view or something ...

Yeah, I find filters fun.
FilterExample2.json

Jean-Pierre Rivière

unread,
Sep 24, 2021, 4:59:50 AMSep 24
to TiddlyWiki
That's fine by me.

And yes filters are fun even if sometimes a bit tricky.

So for the fun of it, you could arrange your filter so that the input would be the 4 tags you want.

something like that:

\define fun(tags)
<$set variable=occ filter="[[$tags]....put your filter code here...count[]]">Seen <<occ>> tiddlers with tags $tags$</$set>
\end

Sometimes, this fun has you coding javascript filter operator. Would this be the case here? I have not thought about it yet.

cheers,

Álvaro

unread,
Sep 24, 2021, 11:39:53 AMSep 24
to TiddlyWiki
It works fine. I tried to find a alternative, but I wasn't lucky.

When I resee your filter, I remember about the multiple parameters in filter operator with commas (from last version, 5.1.23). And we can add a second filter run that it applies your filter to result of first run. Then you can rewrite your filter something like this (in filtering transclusion)
{{{  [tag[Tag 1],[Tag 2],[Tag 3],[Tag 4]]  :filter[tags[]count[]compare:eq[4]]  }}}

Although maybe it be less understandble for you.

Charlie Veniot

unread,
Sep 24, 2021, 12:28:11 PMSep 24
to TiddlyWiki
Oh man, that is pretty awesome.  I can see the majority of the folk loving that.

But you're right, for my disability, that isn't explicit enough for me to distinguish what's going on.

Too many ways of specifying individual tags, and I start getting into some cognitive overload.  I'm the same way when facing a Chinese food buffet, always holding up the line because of too many choices.

Regardless, that is pretty awesome for normal folk who can bounce between the different ways the tag operator can be used.

Charlie Veniot

unread,
Sep 24, 2021, 12:40:21 PMSep 24
to TiddlyWiki
I just discovered the other thing that causes me problems: lack of proximity.

I do find it difficult looking at "Tag 4" in that filter and not seeing the filter operator right before it.  So I see the comma, and I backtrack away from "Tag 4" to figure out the filter operator is "tag".

That back and forth, like long scrolls up and down in a browser window, or back and forward buttons on browsers, all cause dysfunction for this kid.

Thanks, Álvaro.  You just helped me understand a little something there about how I process things, or rather when I can't process things...

Jean-Pierre Rivière

unread,
Sep 24, 2021, 12:52:36 PMSep 24
to TiddlyWiki
I was thinking that the tagging operator was the zay to get tiddlers that all share all of the tags in input. That's what the dec say: "output: the titles of any tiddlers that carry the input tags".

So my function would be:

\define fun(tags)
<$vars four="[tags[]count[]match[4]]">
<$set variable=occ filter="[[$tags$]tagging[] :filter<four>]">Seen <<occ>> tiddlers with tags $tags$</$set>
</$vars>
\end

 But in fact the effect of tagging is "output: the titles of any tiddlers that carry ANY OF the input tags". Too bad for the instance. But I think a correction in the doc would be welcome.


Álvaro

unread,
Sep 24, 2021, 1:15:47 PMSep 24
to TiddlyWiki
I don't know if they are loving that or not. The commas aren't easy to see between brackets (for me). If I begin on end of filter run, i also have this problem. But any can build his/her mental shorcuts to avoid it. If someone can't solve a problem, maybe he/she can create a "alternative way"

Yes, I tried with the tagging operator and I see that behaviour.

Jean-Pierre Rivière

unread,
Sep 24, 2021, 2:30:08 PMSep 24
to TiddlyWiki
For an easy reading, edit your tiddlers with a fixed font like courier or terminal.

Charlie Veniot

unread,
Sep 24, 2021, 8:38:00 PMSep 24
to TiddlyWiki
Or use a text editor that had TiddlyWiki Syntax highlighting when dealing with some complicated stuff:

Screenshot 2021-09-24 9.35.33 PM.png





TW Tones

unread,
Sep 24, 2021, 11:31:18 PMSep 24
to TiddlyWiki
Alvaro;

Have you tested this?

{{{  [tag[Tag 1],[Tag 2],[Tag 3],[Tag 4]]  :filter[tags[]count[]compare:eq[4]]  }}}

I cant see it working. Here is says 

 NEW IN: 5.1.23 Filter operators support multiple parameters which are separated by a  ,  character.

For example: [param1],[param2] or <param1>,{param2}

However as far as I can see only if such multiple parameters are documented in the operator in question.

Tones

Álvaro

unread,
Sep 25, 2021, 8:11:48 AMSep 25
to TiddlyWiki
I don't know if I understand you.

TW Tones

unread,
Sep 25, 2021, 10:02:19 AMSep 25
to TiddlyWiki
Alvaro;

You suggested something like this
{{{ [tag[Tag 1]**,**[Tag 2],[Tag 3],[Tag 4]] :filter[tags[]count[]compare:eq[4]] }}}

As far as I can see this does not work on the pre-release and the t6ag format  [tag[Tag 1],[Tag 2],[Tag 3],[Tag 4]] (simplified)  is not documented

Does not work. So I asked if you tested this?

Eric Shulman

unread,
Sep 25, 2021, 10:18:58 AMSep 25
to TiddlyWiki

I just tested this on both 5.1.23 and 5.2.0pre. I created one tiddler containing

```
{{{ [tag[Tag 1],[Tag 2],[Tag 3],[Tag 4]] :filter[tags[]count[]compare:eq[4]] }}}
```

and another tiddler with the four tags (note capitalization and spaces in the tag values).

It does seem to work on both versions of TW

-e

TW Tones

unread,
Sep 25, 2021, 10:27:45 AMSep 25
to TiddlyWiki
Very interesting. 

I think he documentation should be expanded to detail this. Multiple parameters to operators are only documented in a few operators, but if I read this correctly they can work on operators in general?

If general you may expect this to work ```{{{ [title[tid1],[tid2],[tid3]] }}}``` it does not.
or {{{ [all[current]get[caption],[description]] }}}``` it does not.

TW Tones

unread,
Sep 25, 2021, 10:30:26 AMSep 25
to TiddlyWiki
Of even this {{{ [tag[Common Operators],[HelloThere],[TableOfContents]] }}}

Álvaro

unread,
Sep 25, 2021, 12:00:37 PMSep 25
to TiddlyWiki
- In the fields cases we have a workaround with `fields` operator. It has suffixs (exclude, include)
- I think that there in't any tiddler with those tags. The search is the tiddler with all these tags (¿and any other?)

In the case of titles, you find a issue, but I don't know its reason. I was trying to find a workaround but i wasn't lucky. I also found that the match operator doesn't support multiple parameters.

Télumire

unread,
Sep 27, 2021, 4:58:01 AMSep 27
to TiddlyWiki
Hello all !
The filter syntax provided by @Álvaro  is very neat but doesnt match the requirements of cj.v : counting the tiddlers with 4 specifics tags and only those tiddlers.

See this screenshot  :

https://i.imgur.com/lVlsYZt.png

I think it's because the commas imply an OR condition, but here we want an AND :)

So with a a tiny bit of tweaking the correct filter is :

{{{ [[Tag 1][Tag 2][Tag 3][Tag 4]tagging[]] :filter[tags[]count[]compare:eq[4]] }}}

Here's a live demo :

https://Telumire.github.io/TW-tips/index.html#:%5B%5B4%20tags%20and%20only%20those%204%5D%5D%5B%5B3%20tags%20+%201%20other%5D%5D%5B%5B4%20tags%20and%20one%20more%5D%5D%5B%5BMultiple%20parameters%20separated%20by%20a%20%20,%20%20character%5D%5D

Jean-Pierre Rivière

unread,
Sep 27, 2021, 8:08:07 AMSep 27
to TiddlyWiki
Just a thought: it would be fine if the tagging operator could have a "all" parameter which would select tiddlers tagging all of the tags in input (currently, that's "any tag is enough").

Thus we would have a simple and readable solution as:

{{{ [tag1 tag2 tag3 tag4 +[tagging:all[]]] }}}

Message has been deleted

Charlie Veniot

unread,
Sep 27, 2021, 8:03:03 PMSep 27
to TiddlyWiki
You would need something to wrap tags that have spaces in them.

The "what" to wrap that in, no idea.

TW Tones

unread,
Sep 27, 2021, 8:41:03 PMSep 27
to TiddlyWiki
JP,

One way of handling all tags on the current tiddler is not to use the various tag operators but address the tags field directly.

[all[current]get[tags]] returns the content of the tags field which includes all tags.

Does this meet with your requirement?

Álvaro

unread,
Sep 29, 2021, 6:29:14 PMSep 29
to TiddlyWiki
I think that deleted reply was mine. I will copy and paste from Tiddlytalk

---
@Télumire . It’s true. They works like an OR. {{{ [tag[Tag 1],[Tag 2],[Tag 3],[Tag 4]] }}} also return different result. This behaviour would be documented.
Reply all
Reply to author
Forward
0 new messages