[TW5] Some useful filters (contains, match, overlap)

149 views
Skip to first unread message

Jed Carty

unread,
Nov 4, 2017, 9:51:50 AM11/4/17
to TiddlyWiki
After a question about how to match tiddlers that have two tags and no others I realised once again that we don't have a complete set of logic operations available to us when using tiddlywiki filters. We don't have the ability to directly test a list field in a tiddler against another list. Tobias made a plugin a while ago that address this problem https://tobibeer.github.io/tw5-plugins/#contains but it used some non-tiddlywiki syntax and it overloaded one operator with three separate operations.

Since nothing has been done with this in a while I decided to make three filter operators to fill the gap:

contains, match and overlap

You can see the documentation for them along with examples here.

They work a lot like the listed operator, but with the input and operand switched. I feel that this is much more consistent with how other filter operators work, although both ways have times when they are useful.

The contains operator returns a tiddler if the field given by the suffix of the operator (list by default) contains all of the items listed in the operand. It may contain more than listed in the operand.

The match operator returns a tiddler title if the field contains exactly the same items as the list in the operand, but they don't necessarily have to be in the same order.

The overlap operator returns a tiddler title if there is at least one item that is in both the field in the input tiddler and the operand list.

There are places where each of these can do the same thing as existing filters, but all of them also have unique purposes. I wanted to get some feedback here before I make a pull request.

I would really like to get a better name than 'overlap' for the third operator.

coda coder

unread,
Nov 4, 2017, 10:05:53 AM11/4/17
to TiddlyWiki

On Saturday, November 4, 2017 at 8:51:50 AM UTC-5, Jed Carty wrote:
The overlap operator returns a tiddler title if there is at least one item that is in both the field in the input tiddler and the operand list.

I would really like to get a better name than 'overlap' for the third operator.


Or, perhaps, simply "some".

Coda

coda coder

unread,
Nov 4, 2017, 10:12:58 AM11/4/17
to TiddlyWiki
Jed, btw, in all three documentation tiddlers, you are referencing "overlap" in the body text.

Jed Carty

unread,
Nov 4, 2017, 10:19:52 AM11/4/17
to TiddlyWiki
It is not just the intersection, for filters you just put one operand after the other for an intersection [tag[A]tag[B]] is the intersection of tiddlers with tag A and tiddlers with tag B.

In set theory notation, the three operations are

contains: A ⊆ B (A is a subset of B)
match: A ⊆ B and B ⊆ A (A is a subset of B and B is a subset of A)
overlap: A  B   (The intersection of A and B is not the empty set)

coda coder

unread,
Nov 4, 2017, 10:28:46 AM11/4/17
to TiddlyWiki
Ah, right, "at least one".  Brain fart.

Mark S.

unread,
Nov 4, 2017, 12:05:08 PM11/4/17
to TiddlyWiki
For list 'overlap', maybe 'touches' or 'shares' (or 'sharesone')

Mark

Jed Carty

unread,
Nov 4, 2017, 1:51:44 PM11/4/17
to TiddlyWiki
I made a pull request on GitHub if anyone wants to look at the code https://github.com/Jermolene/TiddlyWiki5/pull/3003

For now I am going to call the operators contains, matches and intersects, hopefully these names are descriptive enough to not be confusing.

TonyM

unread,
Nov 4, 2017, 7:09:26 PM11/4/17
to TiddlyWiki
Great Stuff Jed.

:)
Reply all
Reply to author
Forward
0 new messages