Filter questions

Hi,

I have a couple theoretical questions about filters. Specifically, I’m confused by the documentation examples for the join operator:

a b c d e +[join[,]]

Usually a filter run looks like this:

[!is[system]links[]]

where you have to have the expression within a pair of square brackets. If I do this same with join it won’t work though:

[[a b c d e]join[,]]

So I’m stumped and can’t explain to myself why what I expected to work won’t. Why the + as well?

Thanks in advance!

I’m a big fan of bite-sized discussions.

That is just shorthand for:
[[a]] [[b]] [[c]] [[d]] [[e]] +[join[,]]

Forget about the join for a sec. The following is a hard-coded filter that produces a list using named tiddlers.

[[a]] [[b]] [[c]] [[d]] [[e]]

There is no simpler kind of list. No filter operators !

1 Like

And that is shorthand for:

[title[a]] [title[b]] [title[c]] [title[d]] [title[e]]

“title[a]”, the first filter run between square brackets, says: "give me the list of all tiddlers with the title “a”.

“title[b]”, the next filter run between square brackets, says: "give me the list of all tiddlers with the title “b”.

etc. etc.

1 Like

Ok, cool, but two questions:

  • what’s the plus for?
  • why doesn’t [[a b c d e]join[,]] work? Is that because [a b c d e] is considered a single title?

Thanks again!

From https://tiddlywiki.com/#Filter%20Expression

  • the prefix +, it receives the filter output so far as its input; its output then replaces all filter output so far and forms the input for the next run

So [[a]] [[b]] +[join[, ], The plus says take all items we have so far and string them together, with ", " between each one, into one big item.

Yes, that’s right !

[a b c d e] means the one item defined as “a b c d e”.

The join[, ] is applied between adjoining items. But you only have one item. So there is nothing to join.

Remember: [a b c d e] is shorthand for title[a b c d e], meaning an item with the title “a b c d e”

1 Like

Just for the giggles, toss aside for later if confusing…

Try [[a b c d e]split[ ]].

That says "take the item with the title “a b c d e”, and split the tile into pieces, splitting the title wherever there is a " " (space.) Now we have a list of individual items a, b, c, d, e.

Next, try Try [[a b c d e]split[ ]join[ ]]. That brings us a full circle back to one item: “a b c d e”

i guess what’s confusing is that up to now i’ve been under the impression that a filter must start with [ and end with ] but here it’s 3 different filters right? It’s as if there was an OR between them I guess. Except the last one forces the first two to pass through it.

One filter run is between [ and ]. Then the pieces inside of that make use of [ and ]. But you can’t next more square brackets in those.

[title[a b c d e]split[ ]join[ ]], that is one filter run. “title”, “split” and “join” are operators in that filter, and each operator has as a parameter wrapped in square brackets.

[title[a b c d e]split[ ]join[ ]] [title[f g h i j k]split[ ]join[ ]], that is a case of two filter runs, the resulting list of items from each run combined into one big list.

should be +[join[, ]] right?

that’s actually clear

ARG! Yes. I’ve got an eyeball on the hockey game while I’m typing, and I’m useless at multi-tasking…

I think I understand better now. Thank you. Now here’s a really difficult problem I can’t solve. It’s not directly related to my original question.

<$list filter="[kin:tags:to::{!!tag1}search:tags:some{!!search}]">
<$link to=<<currentTiddler>>/>
<br/>
</$list>

See the tags and some in that filter? I would like to turn those into variables. This doesn’t work for example (replacing some only for brevity):

<$set name="x" value=some>
<$list filter="[kin:tags:to::{!!tag1}search:tags:<x>{!!search}]">
<$link to=<<currentTiddler>>/>
<br/>
</$list>

Can’t figure this out :confused:

Another burning question is this, here’s a filter:

[[blah]search[]]
output: blah

How do I make sure that search returns nothing in that case?

ARG ARG ARG ARG !!!

No, we do not need a “+”

[title[a b c d e]split[ ]join[ ]] . That’s a filter run. Everything between the outer [ and ] is one filter run. No + in there.

Now, say we have two filter runs: [title[a]] and [title[b]]

The actual filter looks like this: [title[a]] [title[b]]

that will result in a list of individual items:

  • a
  • b

If we want these items combined into one comma-separated item, then we want the following flter:

[title[a]] [title[b]] +[join[, ]

So the first filter run generates a list of one item (item “a”):

  • a

The second filter run generates a list of one item (item “b”):

  • b

And then the results of the first filter run and second filter run are combined, and we have:

  • a
  • b

Then the third filter run kicks in. The “+” says "hey, what we are about to do, we want done to all of the items we have so far (items a and b).

So the join applies to the whole bunch of items generated and aggregated during the previous filter runs.

After the third filter run (the join), we have a list with just one item:

  • a, b

awesome, thank you for that explanation. I guess for this to work filters must be evaluated from left to right, one at a time.

I can only think about using a macro there with text substitution. Nothing else seems to work

The problem with TiddlyWiki: too many filter operators.

I’m a minimalist. I toss aside what I consider unfortunate distractions.

Too large a vocabulary does a huge disservice to me. Some call it adding power, I call it unnecessary complexity in regards to learning, communications, documentation, and maintenance/debugging of TW instances.

I’ll only seek out and learn a new operator/feature when it hurts too much not to do that.

What I’ve found: 80% of what I want to do I can easily do with 20% of the plethora of features available.

The other 20% of the stuff I want to do, most of it I can easily do with the same 20% of the features.

It will involve more TW scripting steps, but I understand the steps, and I see clearly what is going on. They are the things I use all of the time, and never any once-in-a-blue-moon stuff I don’t remember how it works.

I tend to obsess about details and can’t fall asleep once i encounter something I don’t understand – not great i know.

@Charlie_Veniot has done a wonderful job of explaining how the outer square braces delinitate a filter run.

  • Delinitating or delimiting something is matching the start and end of something.

eg; [[abba]prefix[a]] the outer [ ] delimits the beginning and end of a filter run, inside the filter run we could call [ ] a default delimiter, in this case we define a title with title[abba] or just [abba]. Only one title inside a filter run then looks like this [[abba]] or this [title[abba]]

However if you introduce a variable or field value they already come with their own delimiters, so we no longer need to use the [ ] for example we use <varname> or {!!fieldname}

[<varname>match{!!fieldname}] would test if the varname matchs the contents of the fieldvalue (on the current tiddler).

  • You will notice we only need one < > or { } inside filters.
  • You can also use {tiddlername} which defaults to the text field {tiddlername!!text}
  • Outside filters, in Wiki text, we have to use doubles << >> {{ }} in part to set them apart from other braces in html such as <div> </div> which use the single < > already.

Proceed below once you feel comphortable with the above

A nice little automatic feature in filters is fieldname[value] for example show-details[yes] will return a value/ be true if the fieldname show-details has the value yes.

  • Notice this show-details[yes] is effectively the same as [title[abba]]

Recent versions also allow macro’s in filters, which are just variables anyway <now YYYY0MM0DD>, put this inside a filter run and rather than use the whole $list widget, we can put the filter in a triple curly braces, or a “filtered transclusion” as follows, {{{ [<now YYYY0MM0DD>] }}}

Tripple braces / filtered transclusions

  • You will see a lot of us using “filtered transclusion”s to test out filters or demonstrate how a filter works.
  • Be aware however if “filtered transclusion”s are used as a parameter such as paramname={{{ filter }}} only the first result is assigned to the parameter.