Search the values of fields where field names are generated?

74 views
Skip to first unread message

amreus

unread,
Aug 29, 2020, 1:31:20 PM8/29/20
to TiddlyWiki

I would like to search all my tiddler's fields that match a regexp /_plac$/

Something like this not-valid syntax:

<$list filter="[fields[]regexp[_plac$]]" variable="flds">
{{{
  [search:<<flds>>[query]]
}}}
</$list>

Is possible?
Thanks.

Mark S.

unread,
Aug 29, 2020, 1:51:08 PM8/29/20
to TiddlyWiki
It will probably work if you just change <<flds>> to <flds> inside the internal filter. Inside of filters, variables use single angle brackets. Outside filters, double angle brackets.

amreus

unread,
Aug 29, 2020, 1:56:14 PM8/29/20
to TiddlyWiki
It is true I am still having difficulty with the appropriate contexts and meanings of the various types and amounts of brackets.

But alas, it did not work.

amreus

unread,
Aug 29, 2020, 2:01:16 PM8/29/20
to TiddlyWiki
I thought to reverse it also - that is search all fields for the term and then filter the titles by the selected fields, but I didn't have any luck with that filter syntax.  It's  possible I just haven't typed the filters correctly.

amreus

unread,
Aug 29, 2020, 2:07:21 PM8/29/20
to TiddlyWiki
Here's is the actual filter. I thought maybe the join is more correct with the search operator:

2020-08-29_140459.png

Eric Shulman

unread,
Aug 29, 2020, 2:24:46 PM8/29/20
to tiddl...@googlegroups.com
On Saturday, August 29, 2020 at 10:31:20 AM UTC-7, amreus wrote:
I would like to search all my tiddler's fields that match a regexp /_plac$/
<$list filter="[fields[]regexp[_plac$]]" variable="flds">
{{{
  [search:<<flds>>[query]]
}}}
</$list>

If I understand your goal correctly, you want to find all fieldnames ending in "_plac" and then search those fields for a value that contains the text "query" and then show the names of the matching tiddlers

If that is the case, then you were very close.  The issue is that filter syntax doesn't permit use of variables in the suffix (e.g. the part after the colon in "search:suffix").

However, you can work around this by using a macro to substitute the variable value into the syntax, like this:
\define searchflds() {{{ [search:$(flds)$[query]] }}}


<$list filter="[fields[]regexp[_plac$]]" variable="flds">
<<searchflds>>
</$list>

-e


Eric Shulman

unread,
Aug 29, 2020, 2:40:50 PM8/29/20
to tiddl...@googlegroups.com
On Saturday, August 29, 2020 at 11:24:46 AM UTC-7, Eric Shulman wrote:
\define searchflds() {{{ [search:$(flds)$[query]] }}}

<$list filter="[fields[]regexp[_plac$]]" variable="flds">
<<searchflds>>
</$list>
 
Addendum:

The above code will work, but... it searches for each field name separately.  As a result, if there are multiple fieldnames in the same tiddler that contain the query text, that tiddler will be listed multiple times.

Your intuition to use "join[,]" to construct a list of fields is actually the better approach.  Thus:
\define searchflds() {{{ [search:$(flds)$[query]] }}}

<$vars flds={{{ [fields[]regexp[_plac$]join[,]] }}}>
<
<searchflds>>
</$vars>

Notes:
* the $vars finds all fieldnames ending in "_plac" and assembles a comma-separated list
* the searchflds macro then uses that list of fieldnames to find the occurrences of "query" within any of those fields

Because the search is looking in all of the "_plac" fieldnames at the same time, any matching tiddlers are only listed once.

-e

amreus

unread,
Aug 29, 2020, 3:53:22 PM8/29/20
to TiddlyWiki
Yes Eric that is exactly what I meant.  It's basically a location search for common gedcom tags (which are not the same as TiddlyWiki tags.) 

Thanks so much for the examples.

I have been reading about macros but I still don't think I grasp them fully yet. However, though experimentation I have come up with the following 2 examples which give me better control over the title lists. The first works fine. I prefer the 2nd example as it's more general.  I think it can generalize even more into a macro named "location-search" maybe. Something similar to <<location-search "California">>

First Example:

\define searchflds()
<$list filter="[search:$(flds)$[California]]">

</$list>
\end


<$vars flds={{{ [fields[]regexp[_plac$]join[,]] }}}>
<<searchflds>>
</$vars>


Second Example:

\define search-filter(term) [search:$(flds)$[$term$]]


<$vars flds={{{ [fields[]regexp[_plac$]join[,]] }}}>
<$list filter=<<search-filter "germany">> >
<$link>{{!!caption}}</$link> {{||year-span}}<br>
</$list>
</$vars>


Reply all
Reply to author
Forward
0 new messages