search operator and variables

292 views
Skip to first unread message

Mohammad

unread,
Dec 12, 2019, 12:59:39 AM12/12/19
to tiddl...@googlegroups.com
Search operator https://tiddlywiki.com/prerelease/#search%20Operator
has flag list, field list and operand! I want to have a list widget and search through some tiddlers pragmatically!
so everything is a variable!


field: transcluded from temp/search/field
term: transcluded from temp/search/term
flag:  transcluded from temp/search/flag


so for example

\define field()  temp/search/field
\define term() temp/search/term
\define flag()  temp/search/flag
\define searchTerm() {{$(term)$!!text}}

<$list filter="[tag[xx]search:{$(field)$}:{$(flag)$}[$(searchTerm)$]]">


</$list>


no success, I know something wrong with variables

Any idea?

--Mohammad

Eric Shulman

unread,
Dec 12, 2019, 2:34:09 AM12/12/19
to TiddlyWiki
There are two problems with your example code:

1) you can't use the $(variable)$ syntax unless you are within a macro
2) The [search:field:flags[...]] filter can't use transclusion for substitution in the field and flags part of the syntax.

Also,
3) If you don't provide a tag value, it won't match anything.  To avoid this, use the tag:strict[...] filter syntax
4) You haven't provided any control over what kinds of tiddlers to search.  To add this, put an all[...] filter at the beginning

Here's my solution, which I have uploaded to http://tiddlytools.com/filtergenerators.html

\define tidinput()   $:/temp/search/tid
\define taginput()   $:/temp/search/tag
\define fieldinput() $:/temp/search/field
\define terminput()  $:/temp/search/term
\define flaginput()  $:/temp/search/flag
\define doSearch()
<$vars filter="""[all[$(tids)$]tag:strict[$(tag)$]search:$(field)$:$(flag)$[$(term)$]]""">
There are <$count filter=<<filter>>/> tiddlers matching ''<$text text=<<filter>>/>''
<blockquote>
   
@@.columns3.small <$list filter=<<filter>>><$link/><br></$list>@@
</blockquote>
</
$vars>
\end

|                                tiddlers to search:|<$edit-text tiddler=<<tidinput>>   tag="input" default="" placeholder="tiddlers"          />|
|                                    tag for search:|<$edit-text tiddler=<<taginput>>   tag="input" default="" placeholder="enter a tag"       />|
| field(s) for search (comma-separated field names):|<$edit-text tiddler=<<fieldinput>> tag="input" default="" placeholder="title,text,tags"   />|
|     flag(s) for search (comma-separated keywords):|<$edit-text tiddler=<<flaginput>>  tag="input" default="" placeholder="words"             />|
|                                text to search for:|<$edit-text tiddler=<<terminput>>  tag="input" default="" placeholder="enter search text" />|
<$vars
  tids
={{{ [<tidinput>get[text]]   ~[[tiddlers]]        }}}
   tag
={{{ [<taginput>get[text]]                        }}}
 field
={{{ [<fieldinput>get[text]] ~[[title,text,tags]] }}}
  flag
={{{ [<flaginput>get[text]]  ~[[words]]           }}}
  term
={{{ [<terminput>get[text]]                       }}}>
   
<<doSearch>>
</$vars>

enjoy,
-e

Mohammad

unread,
Dec 12, 2019, 3:34:23 AM12/12/19
to TiddlyWiki


On Thursday, December 12, 2019 at 11:04:09 AM UTC+3:30, Eric Shulman wrote:
On Wednesday, December 11, 2019 at 9:59:39 PM UTC-8, Mohammad wrote:
Search operator https://tiddlywiki.com/prerelease/#search%20Operator
has flag list, field list and operand! I want to have a list widget and search through some tiddlers pragmatically!
so everything is a variable!

field: transcluded from temp/search/field
term: transcluded from temp/search/term
flag:  transcluded from temp/search/flag

so for example
\define field()  temp/search/field
\define term() temp/search/term
\define flag()  temp/search/flag
\define searchTerm() {{$(term)$!!text}}

<$list filter="[tag[xx]search:{$(field)$}:{$(flag)$}[$(searchTerm)$]]">


</$list>
no success, I know something wrong with variables


Many thanks Eric!
 
There are two problems with your example code:

1) you can't use the $(variable)$ syntax unless you are within a macro
That is right! I use the $list in above code inside a macro!
 
2) The [search:field:flags[...]] filter can't use transclusion for substitution in the field and flags part of the syntax.
I did not know this, it seems only operand can be directly transcluded!

Also,
3) If you don't provide a tag value, it won't match anything.  To avoid this, use the tag:strict[...] filter syntax

I do not understand this quite well! I have seen this before in https://tiddlywiki.com/prerelease/#tag%20Operator
what really strict does mean here?
 
4) You haven't provided any control over what kinds of tiddlers to search.  To add this, put an all[...] filter at the beginning
Isn't it it assume all[tiddlers] ?

Here's my solution, which I have uploaded to http://tiddlytools.com/filtergenerators.html

This is great! A one place for filter solution and for later use! a codepen like for Tiddlywiki (live experimenting)
I will email David to add to tiddlywiki toolmap!
Comments:
  • I understand $var widget has filter input parameter, not documented and I always use set for this purpose
  • I should be able to use regexp as search flag and this will give higher flexibility

Thanks again! Every answer like this is small lesson in wikitext scripting.
 
enjoy,
-e

Mohammad

unread,
Dec 12, 2019, 3:37:57 AM12/12/19
to TiddlyWiki
Minor comment
The http://tiddlytools.com/filtergenerators.html site title is good to change to reflect the purpose like Filter Generator.

--Mohammad

Eric Shulman

unread,
Dec 12, 2019, 4:18:24 AM12/12/19
to TiddlyWiki
On Thursday, December 12, 2019 at 12:34:23 AM UTC-8, Mohammad wrote:
On Thursday, December 12, 2019 at 11:04:09 AM UTC+3:30, Eric Shulman wrote:
3) If you don't provide a tag value, it won't match anything.  To avoid this, use the tag:strict[...] filter syntax

I do not understand this quite well! I have seen this before in https://tiddlywiki.com/prerelease/#tag%20Operator
what really strict does mean here?


if T (the tag value) is missing then the output of tag is empty, and the output of !tag is a copy of the input.
if T (the tag value) is missing and S (the suffix) is set to "strict", then the output of both tag and !tag is a copy of the input

thus, tag[] results in an empty list, while tag:strict[] is a "pass-thru" of whatever came before it in the filter
 
4) You haven't provided any control over what kinds of tiddlers to search.  To add this, put an all[...] filter at the beginning
Isn't it it assume all[tiddlers] ?

yes... that is correct... but I wanted to give more selective control... so you can say all[tiddlers+shadows], all[shadows], all[orphans], etc.

Here's my solution, which I have uploaded to http://tiddlytools.com/filtergenerators.html

This is great! A one place for filter solution and for later use! a codepen like for Tiddlywiki (live experimenting)
I will email David to add to tiddlywiki toolmap!

thanks.  I've collected a few of my "filter generator" solutions in that file, and now that I've got
TiddlyTools.com hosting working again, I'm keeping an online copy for sharing.

Comments:
  • I understand $var widget has filter input parameter, not documented and I always use set for this purpose

Technically, $vars doen't have it's own filter handling... it's just that it can use the {{{ [...] }}} syntax for parameters, just like any other widget.

One important difference between the <$set name="foo" filter="[...]"> and <$vars foo={{{ [...] }}}> syntax:

the results of a $set filter can be a list of values, while the {{{ [...] }}} syntax only returns the *first* value in the list
  • I should be able to use regexp as search flag and this will give higher flexibility
yes.  The flag values are defined here: https://tiddlywiki.com/#search%20Operator

note:  you can use * (asterisk) for the "field" value, so it searches ALL the fields in a tiddler, instead of just the ones that are explicitly mentioned.

e.g. search:*[foo] will find "foo" in ANY field

also, if you want to search all fields EXCEPT for certain ones, you add a leading "-" (minus sign) to the field value

e.g. search:-title[foo] will find "foo" in ANY field EXCEPT the tiddler title
 
Thanks again! Every answer like this is small lesson in wikitext scripting.

You're welcome!  As I say in my usual closing:

enjoy,
-e 

Mohammad

unread,
Dec 12, 2019, 4:34:05 AM12/12/19
to TiddlyWiki
Many thanks for clarification!

--Mohammad

Eric Shulman

unread,
Dec 12, 2019, 10:17:09 AM12/12/19
to TiddlyWiki
On Thursday, December 12, 2019 at 12:37:57 AM UTC-8, Mohammad wrote:
The http://tiddlytools.com/filtergenerators.html site title is good to change to reflect the purpose like Filter Generator.

As you've suggested, I've added a $:/SiteTitle and $:/SiteSubtitle.  I've also updated the FilterGenerator/Search definition:

* Added support for specifying a "prefix[...]" in the filter
* Added a delete button (with modal confirm) to delete matching tiddlers
* Renamed to "FilterGenerator/SearchAndDestroy"

enjoy,
-e

Eric Shulman

unread,
Dec 12, 2019, 10:54:00 AM12/12/19
to TiddlyWiki
I just added an "export" button to SearchAndDestroy
so you can now use it just like the $:/AdvancedSearch/Filter panel
except that you don't need to hand-write the filter.

enjoy,
-e

Mohammad

unread,
Dec 12, 2019, 12:35:44 PM12/12/19
to TiddlyWiki
Looks great!  I am sure this wiki will get a lot of attention.
Filter is a fundamental area in Tiddlywiki always users specially newcomers get confused!

It is nice to see what is the form of filter produce that list of tiddlers.

Thank you Eric!

--Mohammad

Mohammad

unread,
Dec 12, 2019, 12:43:17 PM12/12/19
to TiddlyWiki
This is very useful specially for who not very familiar with filter details!
Also SearchAndDestroysupport regexp which is very useful!

--Mohammad
 

enjoy,
-e

TonyM

unread,
Dec 12, 2019, 3:49:33 PM12/12/19
to TiddlyWiki
Mohammad et all

A design pattern I use to simplify similar code is turning text references or transcludes into variables

\define sitetitle() {{$:/SiteTitle}}
\define sitesubtitle() {{$:/SiteSubtitle}}

These can be global variables as well

One advantage being variables can be reset with a local variable or field.

<$set name=sitetitle value={{!!sitetitle-field}} emptyValue=<<sitetitle>> >

Note how the new value can be sourced anywhere and you can even reuse the variable name, which is a kind of override.

This method allows fields, tiddlers and text references to become variables, All that is missing is the ability to allow variables to become fields, tiddlers and text references without a trigger button. Since the view widget does not accept variable input we have a serious gap. I plan to make a workaround soon.

Regards
Tony

Mohammad

unread,
Dec 12, 2019, 4:07:02 PM12/12/19
to TiddlyWiki
Good point Tony!
I think TiddlyTables has a lot to learn and what you said is used throughout TiddlyTables code!

--Mohammad

HansWobbe

unread,
Dec 13, 2019, 7:19:35 AM12/13/19
to TiddlyWiki
Gentlemen:

This is a really useful piece of work and your comments are quite enlightening.

Thank you for sharing this!

Best regards,
Hans

Message has been deleted

Eric Shulman

unread,
Dec 19, 2019, 5:54:26 AM12/19/19
to TiddlyWiki
Another update to http://tiddlytools.com/filtergenerators.html SearchAndDestroy

* added "clear inputs" button: [X]
* added edit-list macro (combines $edit-field widget with droplist to select values)
   - allows typing input OR selecting from droplist
   - used in SearchAndDestroy to enter "tiddlers to search" input

enjoy,
-e



Mohammad

unread,
Dec 19, 2019, 9:51:53 AM12/19/19
to TiddlyWiki
Hi Eric,
 Thanks for the update!
This is a great tool to learn filter! and also create custom search UI.

I also added a limit[n] for cases search result in a  big number of tiddlers

--Mohammad

Magnus

unread,
Dec 19, 2019, 7:21:28 PM12/19/19
to TiddlyWiki
Not to nitpick, but would be even more ultraperfekt if there where possible to use NOT (checkbox to negate [system + shadow] for example) :)

Eric Shulman

unread,
Dec 21, 2019, 5:35:21 PM12/21/19
to TiddlyWiki
Yet another big update to http://tiddlytools.com/filtergenerators.html SearchAndDestroy

* I added individual "reset" buttons for each part of the input table, so you can clear each separately (the existing "clear all" button still applies to all inputs at once)
* use of my "edit-list" macro for all inputs (except the search term itself) to provide combined edit-text and select list functionality.  This allows you to enter values or pick pre-defined values from a list.  Note that the edit-text fields use the "focusPopup" feature to automatically show the list as soon as you put the cursor in the edit field.
* some of the lists are 'self-filtering' so that as you type, the list choices are automatically updated to only show items that contain the current input text.
* the "prefix" edit-list has a separate button that adds/removes a long, auto-generated list of system tiddler "folders" making it easier to use for exploring the core shadows (which has nearly 2000 tiddlers!)
(be sure to select "shadows" or "tiddler+shadows" in the first edit-list, so that the results will actually find shadow definitions)
* rather than limiting the output (using "limit[n]", as you have done), I added "overflow-y:auto" and "max-height:50vh" styles to the output display, so that you can scroll through the results

-e

Mohammad

unread,
Dec 22, 2019, 12:30:38 AM12/22/19
to TiddlyWiki
This is an All-in-One search tools! (it is a run and learn tool!)
I appreciate to put these description in SearchAndDestroy documentation tiddler!

Best
Mohammad
Reply all
Reply to author
Forward
0 new messages