[tw5] Just a Filtering Code Pattern

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 (798 Bytes)

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 <> 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,

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.

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.

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…

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]">Seen <> 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.

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.

For an easy reading, edit your tiddlers with a fixed font like courier or terminal.

Or use a text editor that had TiddlyWiki Syntax highlighting when dealing with some complicated stuff:

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 ,{param2}

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

Tones

I don’t know if I understand you.

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?

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

1 Like

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.

Of even this {{{ [tag[Common Operators],[HelloThere],[TableOfContents]] }}}

1 Like
  • 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.

1 Like

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 :

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

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#:[[4%20tags%20and%20only%20those%204]][[3%20tags%20+%201%20other]][[4%20tags%20and%20one%20more]][[Multiple%20parameters%20separated%20by%20a%20%20,%20%20character]]

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[]]] }}}

You would need something to wrap tags that have spaces in them.

The “what” to wrap that in, no idea.

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?