Breaking up very long runs in a filter?

117 views
Skip to first unread message

Cade Roux

unread,
Sep 30, 2020, 1:41:23 PM9/30/20
to TiddlyWiki
What is the best technique to break up very long runs in a filter (preferably to different lines)?  Can't use whitespace since that separates runs.  I have a filter that is currently 382 characters.

It selects a subset of tiddlers on one field, then four other fields individually have to have tags matching four dropdowns which allow the user to filter, and then it is sorted.  Some of that can be mitigated with shorted field names, but it still is unwieldy in most editors.

Thanks,

Cade

Joshua Fontany

unread,
Sep 30, 2020, 7:22:25 PM9/30/20
to TiddlyWiki
You can define sections of that filter as macro definitions, and then call them with "subfilter<macroFilter1>".

I.e. "[all[tiddlers+shadows]tag[MyTag]subfilter<macroFilter1> subfilter<macroFilter2> sort[]]" 

Define them at the start of the tiddler which is using the filter, or define them in other tiddlers and import using the "\import filter-to-import" Pragma at the top of the text field where the filters will be used.

Best,
Joshua Fontany

Cade Roux

unread,
Sep 30, 2020, 7:47:41 PM9/30/20
to TiddlyWiki
You have an example I can look at somewhere?  I just tried to extract one of the filters and it doesn't appear to be working - probably because of the curlybracket reference to the value of another tiddler set by the dropdowns?

\define obsname()
contains:ascend.observation.name{$:/ascend/state/observation.name.selected}
\end

Then I tried to use it as subfilter<obsname> in the filter where that original filter was and the filter no longer works as expected.

I think I need to make up a toy version of this wiki so people can see it in action.

Thanks,

Cade

TW Tones

unread,
Sep 30, 2020, 8:34:27 PM9/30/20
to TiddlyWiki
Cade,

Sub filters need to be full syntactically correct filters in their own right, in fact this may allow you to test them independently of your larger combined filter. 

Subfilters that respond to the filters so far are appended as such 
restoffilter]subfilter<filter-varname>] <= end of run
restoffilter
]subfilter<filter-varname>nextoperator[] <= continue run
[subfilter<filter-varname>] <= a run on its own which generates its output along with other runs

However rather than make large compound filters I like to break the problem down and build nested lists with each handling part of the filter.
  • The advantage here is you can output intermediate results
This snipit shows how one list provides input to another (if you are not making use of the currentTiddler

<$list filter="firstfilter eg get states" variable=each-state>
  Show State<
<each-state>><br>
   <$list filter="[
<each-state>get towns" variable=each-town>
     Show Town <
<each-town>><br>
   </$list>
</$list>
Once you have your complex filter working you can remove the show lines you don't want, and have only the output you intended
  • This helps building and debugging, now and subsequently.
  • This helps reuse and repurposing because it is more self documenting than a single filter
  • In very few cases is this nesting has much greater overheads than a single filter.
  • Combine this with a few subfilters that are also reusable, and can be defined in tiddlers using the $:/tags/Macro tag

In time you will also learn how to write such nested lists to once working convert it to one long single filter if you want. 

Such filters can be placed in a filter field of a tiddler tagged $:/tags/Filter and a few other settings to make the filter available in the advanced search filter drop down;

Then you then can also use filter={{tiddlername!!filter}} or filter="[{tiddlername!!filter}] in your filter parameter.

Regards
Tony

Joshua Fontany

unread,
Sep 30, 2020, 8:53:13 PM9/30/20
to TiddlyWiki
As Tony mentioned, subfilters have to be "complete filter runs", not just a series of operators. Try this, with the enclosing square-brackets:


\define obsname()
[contains:ascend.observation.name{$:/ascend/state/observation.name.selected}]
\end

"subfilter<obsname>" in your main filter will then pass each individual title to the subfilter as input, returning all that pass.

Best,
Joshua F

amreus

unread,
Oct 2, 2020, 4:09:50 AM10/2/20
to TiddlyWiki
Just to add a hopefully helpful example.  You can store filters not only as macros, but in fields and data tiddlers.

While learning and experimenting with some wikis I was inconsistent in my use of tags.  I used a data tiddler to define filters until I got things cleaned up and simplified.

filter data-tidder:

title:filters
tasks:[tag[task]] [tag[Task]] [tag[Item]]

use:

<$list filter="[subfilter{filters##tasks}!tag[Done]]" template="task-template"/>


Reply all
Reply to author
Forward
0 new messages