Filter based on integer field values less than or equal to

252 views
Skip to first unread message

Sean Hankins

unread,
Sep 30, 2020, 4:34:39 PM9/30/20
to TiddlyWiki
I'm looking for a way to get tiddlers based on comparing integer fields existing in them. This filter works:

[myfieldOne[2]myfieldTwo[2]]

I'd like something like:

[myfieldOne[lteq[2]]myfieldTwo[lteq[2]]]  

I know there are compare operators (https://tiddlywiki.com/#compare%20Operator), but I haven't figured out how to use it to filter the lists. Would this require a subfilter? If so, how would that look? 

Thanks!
Sean

Joshua Fontany

unread,
Sep 30, 2020, 7:03:09 PM9/30/20
to TiddlyWiki
The core "compare[X]" operator only compare each "input title" to the operand (i.e. X). It has options to compare strings, numbers, equal to, greater than, etc.... BUT the limitation of only comparing input-title means you would have to use "get[]" or similar to retrieve the data, thus losing the "title" during the filter-processing.

I don't think "subfilter[]" will help here, because the compare[] op, as I said, returns the data that passes the compare-function given, NOT the title.

So I rolled my own. It is included in the JSONMangler plugin, but can be pulled into any wiki if you go to the plugin-contents tab, and drag the filter you want to your own wiki:

http://chronicles.wiki/TW5-JsonMangler/#%24%3A%2Fplugins%2Fjoshuafontany%2Fjsonmangler

You will want to drag and drop the
  • $:/plugins/joshuafontany/jsonmangler/modules/filters/comparefield.js
 link in the contents tab.

Best,

Joshua Fontany

Joshua Fontany

unread,
Sep 30, 2020, 7:04:36 PM9/30/20
to TiddlyWiki
Basic documentation: http://chronicles.wiki/TW5-JsonMangler/#comparefield%20Operator

Best,
Joshua Fontany

Sean Hankins

unread,
Sep 30, 2020, 8:21:24 PM9/30/20
to TiddlyWiki
Wow! That's brilliant. I went ahead and grabbed that whole plugin. Thanks a bunch!

Sean

History Buff

unread,
Nov 29, 2020, 2:14:16 PM11/29/20
to TiddlyWiki
Joshua,

I stumbled on this thread today while searching for "less than" in this group. Your compare fields filter is exactly what I was looking for! Thanks so much. It works amazingly.

Damon

Message has been deleted

Damon Pritchett

unread,
Nov 29, 2020, 2:19:38 PM11/29/20
to tiddl...@googlegroups.com
Thanks Jeremy,

I saw that, but it was my understanding that it only operated on tiddler titles. I need it to operate on a custom field. 

Cheers,

Damon 


On Sun, Nov 29, 2020 at 12:16 PM Jeremy Ruston <jeremy...@gmail.com> wrote:
Hi Damon

We now have a compare operator in the core that can do "less than" comparisons on numbers, dates and strings:


Jeremy


On 29 Nov 2020, at 19:14, History Buff <damon.p...@gmail.com> wrote:

Joshua,


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/5820178b-d886-4c70-9c05-b44a4f9d0868n%40googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/EfRToFFXCh0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/E9085145-120E-4319-BE14-189DCA73F711%40gmail.com.

Jeremy Ruston

unread,
Nov 29, 2020, 3:16:33 PM11/29/20
to tiddl...@googlegroups.com
Hi Damon
I saw that, but it was my understanding that it only operated on tiddler titles. I need it to operate on a custom field. 

Apologies, I hadn't noticed that Joshua had already referenced the core compare operator. I deleted my message and hoped that nobody had noticed!

Best wishes

Jeremy


Eric Shulman

unread,
Nov 29, 2020, 3:19:43 PM11/29/20
to TiddlyWiki
On Wednesday, September 30, 2020 at 1:34:39 PM UTC-7 scarab...@gmail.com wrote:
I'm looking for a way to get tiddlers based on comparing integer fields existing in them. This filter works:
[myfieldOne[2]myfieldTwo[2]]
I'd like something like:
[myfieldOne[lteq[2]]myfieldTwo[lteq[2]]]  
I know there are compare operators (https://tiddlywiki.com/#compare%20Operator), but I haven't figured out how to use it to filter the lists.

To compare a single field value with an integer, returning the tiddler title:
[<currentTiddler>get[myfieldOne]compare:integer:lteq[2]then<currentTiddler>]

To compare two different field values with integers, returning the tiddler title:
[<currentTiddler>get[myfieldOne]compare:integer:lteq[2]then<currentTiddler>get[myfieldTwo]compare:integer:lteq[2]then<currentTiddler>]

Note that each field must exist AND have a value (i.e., not blank)

enjoy,
-e

TW Tones

unread,
Nov 29, 2020, 9:41:58 PM11/29/20
to TiddlyWiki
History 1Buff,

I will just add to Erics note that when you cause the value of a field or macro etc.. to be available as the result of a filter each item, is considered a "title" even if their is not a tiddler with that title.

Eg;
<$list filter="[range[1,10]]">

</$list>
In side the list the currentTiddler title will be 1,2,3 - 10

Regards
Tones

Sean Hankins

unread,
Nov 30, 2020, 2:06:31 PM11/30/20
to TiddlyWiki
Eric,
Great tips there! I'll still recommend Joshua Fontany plugin, however, for clarity and ease of use.

Another tip on top of Tones comment; Looping through a list will automatically overwrite the variable "currentTiddler", so if you want to retain access to the tiddler you are working in, you will have to use the "variable" argument in the list:

E.g.:
/* without 'variable' */
<$list filter="[range[1,10]]">
<<currentTiddler>>
</$list>
/* output: 1 2 3 4 5 6 7 8 9 10 */

/* with 'variable' */
<$list filter="[range[1,10]]" variable="mynumber">
<<mynumber>>:<<currentTiddler>>
</$list>
/* output: 1:MyTitle 2:MyTitle 3:MyTitle 4:MyTitle 5:MyTitle 6:MyTitle 7:MyTitle 8:MyTitle 9:MyTitle 10:MyTitle */

History Buff

unread,
Nov 30, 2020, 4:43:21 PM11/30/20
to TiddlyWiki
I agree that Joshua's plugin is much easier and clearer to use. Took me two minutes to install and implement exactly what I needed. At least for the way my brain works, it's much more intuitive.

Damon

Joshua Fontany

unread,
Dec 2, 2020, 9:23:44 PM12/2/20
to TiddlyWiki
You will be able to do this with core TW5 syntax once the new filter operators with 5.1.23 are released.

With the new "filter[]" operator, each input title is compared to the filter given, and the TITLE of any matches are returned (instead of the result of the subfilter being returned, as in the "subfilter[]" operator). It is still a lot of syntax, though, in the base form:

<$set $name="compareFilter" $value="[get[field_name]compare:integer:lteq  [100]]">
<$list $filter="[all[tiddlers]tag[CompareList]filter<compareFilter>]">

<<<currentTiddler>>
</$list>
</$set>

And it gets complicated when you want to change the field or index to compare to, but does offer more flexibility.

Best,
Joshua F

TW Tones

unread,
Dec 3, 2020, 1:49:32 AM12/3/20
to TiddlyWiki
Joshua,

Can we say the new filter operator is specifically a "title Filter", although it is true titles can be many things including non existent, or literal values. 

Regards
Tones

Saq Imtiaz

unread,
Dec 3, 2020, 4:18:07 AM12/3/20
to TiddlyWiki
To add on to Joshua's solution based on 5.1.23 you can also do this:

<$list $filter="[all[tiddlers]tag[CompareList]] :filter[get[field_name]compare:integer:lteq[100]]">

<<<currentTiddler>>
</$list>


Reply all
Reply to author
Forward
0 new messages