Map Filter Run Prefix and Filter Constructors

A filter like below does not work!

[all[current]] :map[all[tiddlers]search:text<currentTiddler>]
[all[current]] :map[all[tiddlers]search:caption<currentTiddler>]

Isnt it that the [all[]] is filter constructor? So why the the result from line 1 passed to line 2? I expect to separate filter runs and dedup result!

Using a constructor only ensures that any previous input is ignored within the run to generate the output of that run.

Is that a simplified example of your actual filter expression? If so, sharing the original may facilitate conversation. Or consider explaining what you are trying to achieve as the objective of using map in the above expression is not clear.

To search the text and caption fields of all tiddlers for the current tiddler you can specify both fields when calling the search operator:

[all[tiddlers]search:caption,text<currentTiddler>]
1 Like

If I’m guessing it right, you would have a tiddler named “bench” for instan.ce where you would like to show or otherwise use all the titles of tiddlers that have “bench” in their text body.

Then there can be a lot of results. So you don’t have to use :map that allows only for one result.

Instead, you can write :

[all[tiddlers]search:text<currentTiddler>]

which is what @saqimtiaz told you (with both text and title).

1 Like

Thank you @saqimtiaz .
The actual usecase is related to my previous question (Filter and Regexp Patterns to Find Transclusion and Back Transclusion) and the solution I got!

Real use-case: I was looking for transclusion and backtransclusion in just one filter

so I wrote (using solution by @telumire and @Mohammad, and @Yaisog) in a viewtemplate:

\define trans-patt() {{$(currentTiddler)$.*}}
\define escapechars-pattern() ([\?\.\*\+\(\)\$\^\\])

<$list filter="""
[all[current]get[text]search-replace:gm:regexp[{{\s*(.*?)\s*(?:}}|\|\||!!)],[###start###$1###end###]split[###start###]] :map[split[###end###]]]
[all[current]search-replace:g:regexp<escapechars-pattern>,[\$1]] :map[all[tiddlers]regexp:text<trans-pattern>]"
""">

</$list>

It seems these are not two separate filters. The first line is passed to second while I have started my second line with [all[...]] which is a filter constructor.

That is the expected behaviour. Dividing filters into separate lines does not make them separate filters, the line break is just formatting. Your code shows a single filter expression consisting of 4 filter runs. As I explained, the use of a filter constructor only ignores any previous input within that filter run to generate its output. It does not exclude that previous input from further runs.

I recommend studying the difference between a filter expression and a filter run. See https://tiddlywiki.com/#Filter%20Syntax

You may also find the trim operator to be useful in the use case you have given:
https://tiddlywiki.com/#trim%20Operator

2 Likes

Thank you Saq!
I will read the docs you introduced.