[TW5] Search in field contents?

2,142 views
Skip to first unread message

cmari

unread,
Sep 7, 2014, 12:58:20 PM9/7/14
to tiddl...@googlegroups.com
I find myself using a lot of fields, and I wonder if anyone has come up with an easy way to search for the contents of fields.  As best I can tell, you need to know a field's name in order to search for its contents? 
As an example, two of the publications in the demo at http://tw5.scholars.tiddlyspot.com/ are books and are labelled as such in a field.  However, a search for the word "book" will not find them.  You need to know know that the field where the information is stored is called "publication type", you need to go to advanced search, and you need to put [publication_type[book]] into the filter search.  Note that I am in no way criticizing Alberto's great tool (I know he has other ways of identifying books and I'm a happy adapter of his approach). I'm just wondering if there is a quicker way to find all the tiddlers that contain the word book in their fields.

Thanks - and as always, apologies if I missed an answer that's already been given.
cmari

Stephan Hradek

unread,
Sep 8, 2014, 3:01:34 AM9/8/14
to tiddl...@googlegroups.com
Create this tiddler:

\define searchInField(field, for)

<$list filter="[!is[shadow]!is[system]field:$field$/$for$/]">

<$link><$view field="title"/></$link>

</$list>

\end

<$list filter="[!is[shadow]!is[system]fields[]]" variable="fieldname">

Searching in field: <<fieldname>>

<$macrocall $name="searchInField" field=<<fieldname>> for={{$:/
temp/search}}/>

</$list>


And type your search text in the standard search field.

Stephan Hradek

unread,
Sep 8, 2014, 3:05:21 AM9/8/14
to tiddl...@googlegroups.com
Small enhancement:

\define searchInField(field, for)

<$list filter="[!is[shadow]!is[system]field:$field$/$for$/]">

<$link><$view field="title"/></$link>

<
/$list>

\end

<$reveal state="$:/
temp/search" type="nomatch" text="">
<$list filter="
[!is[shadow]!is[system]fields[]]" variable="fieldname">


Searching in field: <<fieldname>>

<$macrocall $name="
searchInField" field=<<fieldname>> for={{$:/temp/search}}/>

</$list>
</$reveal>


This will hide the results when no search text was entered.

cmari

unread,
Sep 12, 2014, 11:28:11 AM9/12/14
to tiddl...@googlegroups.com
Hi Stephan,
Thanks, that led me down an interesting rabbit-hole. I had to use $:/temp/advancedsearch instead of $:/temp/search in order to get any results. Then of course, I got results for *all* fields (which of course was what I asked for - but quickly realized I didn't actually want!).  I tweaked things to exclude fields in which the search term wasn't found.  I'd really like to also exclude the fields "title", "text", and "tags", but I couldn't figure out how to do that (and my fumbling efforts produced many javascript errors and hung pages). Here's what I came up with, in case it's of interest:

\define searchInField(field, for)
<$list filter="[!is[shadow]!is[system]field:$field$/$for$/]">$field$:
<ul><li><$link><$view field="title"/></$link> </li></ul></$list>
\end
<$reveal state="$:/temp/advancedsearch" type="nomatch" text="">

<$list filter="[!is[shadow]!is[system]fields[]]" variable="fieldname">
<$macrocall $name="searchInField" field=<<fieldname>> for={{$:/temp/advancedsearch}}/>
</$list>
</
$reveal>

cmari

Jeremy Ruston

unread,
Sep 12, 2014, 11:36:42 AM9/12/14
to TiddlyWiki
Hi cmari

You can exclude fields like this:

\define searchInField(field, for)
<$list filter="[!is[shadow]!is[system]field:$field$/$for$/]">$field$: 
<ul><li><$link><$view field="title"/></$link> </li></ul></$list>
\end
<$reveal state="$:/temp/advancedsearch" type="nomatch" text="">

<$list filter="[!is[shadow]!is[system]fields[]] -title -text -tags" variable="fieldname">
<$macrocall $name="searchInField" field=<<fieldname>> for={{$:/temp/advancedsearch}}/> 
</$list>
</
$reveal>

Best wishes

Jeremy


--
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 post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

cmari

unread,
Sep 12, 2014, 11:57:23 AM9/12/14
to tiddl...@googlegroups.com
thanks, that's so simple (and powerful) that it makes me feel really stupid for not having known about it!
cmari

Dmitry Skopa

unread,
Dec 27, 2014, 10:13:46 PM12/27/14
to tiddl...@googlegroups.com
Hello, Stephan

Do I need to name this tiddler in some special way or tag it with some special tag to make it work?

I added this content to a tiddler named SearchInFields, and typing to a standart search field didn't change.

Stephan Hradek

unread,
Dec 28, 2014, 2:50:48 PM12/28/14
to tiddl...@googlegroups.com


Am Sonntag, 28. Dezember 2014 04:13:46 UTC+1 schrieb Dmitry Skopa:
Hello, Stephan

Do I need to name this tiddler in some special way or tag it with some special tag to make it work?


No. Just take care to remove the line breaks which appeared somehow in the code :(

\define searchInField(field, for)

<$list filter="[!is[shadow]!is[system]field:$field$/$for$/]">

<$link><$view field="title"/></$link>

<
/$list>

\end

<$reveal state="$:/
temp/search" type="nomatch" text="">
<$list filter="
[!is[shadow]!is[system]fields[]]" variable="fieldname">



Searching in field: <<fieldname>>

<$macrocall $name="
searchInField" field=<<fieldname>> for={{$:/temp/search}}/>

</$list>
</$reveal>

 

Stephan Hradek

unread,
Dec 28, 2014, 3:09:50 PM12/28/14
to tiddl...@googlegroups.com
As an update:

Create a tiddler called "Field" tagged "$:/tags/AdvancedSearch" containing:

\define searchInField(field, for)

<$list filter="[!is[shadow]!is[system]field:$field$/$for$/]">

<$link><$view field="title"/></$link>

<
/$list>

\end


<$edit-text tiddler="$:/
temp/advancedsearch" type="search" tag="input"/> <$select field="fieldname" tiddler="$:/temp/advancedsearch">
<option value="
Any">Any</option>
<$list filter="
[!is[shadow]!is[system]fields[]sort[]]" variable="fieldname">
<option value=<<fieldname>>><<fieldname>></option>
</$list>
</$select>

<$reveal state="
$:/temp/advancedsearch" type="nomatch" text="">
<$reveal state="
$:/temp/advancedsearch!!fieldname" type="match" text="Any">
<$list filter="
[!is[shadow]!is[system]fields[]]" variable="fieldname">


Searching in field: <<fieldname>>

<$macrocall $name="
searchInField" field=<<fieldname>> for={{$:/temp/advancedsearch}}/>

</$list>
</$reveal>
<$reveal state="
$:/temp/advancedsearch!!fieldname" type="nomatch" text="Any">

Searching in field: {{$:/temp/advancedsearch!!fieldname}}

<$macrocall $name="
searchInField" field={{$:/temp/advancedsearch!!fieldname}} for={{$:/temp/advancedsearch}}/>

</$reveal>

</$reveal>


You'll get an additional "Advanced Search tab where you can search in all or just one field for values.

Dmitry Skopa

unread,
Dec 29, 2014, 8:54:21 AM12/29/14
to tiddl...@googlegroups.com
Oh, I got it: I was looking for search results in the standard search panel, but they were in this tiddler itself.

Now can I somehow include this output in the standard search panel (not advanced)?

Tobias Beer

unread,
Dec 31, 2014, 5:33:46 AM12/31/14
to tiddl...@googlegroups.com
Hi Stephan,

This is very useful. I slightly modified it and added it here...


Smells like a core feature to me.

Best wishes, Tobias.

Alberto Molina

unread,
Dec 31, 2014, 7:47:06 AM12/31/14
to tiddl...@googlegroups.com
Thanks Stephan!

Very useful, but with one little flaw: it is case sensitive. How to avoid that?

Regards,

Alberto

Jeremy Ruston

unread,
Dec 31, 2014, 11:15:05 AM12/31/14
to TiddlyWiki
Hi Tobias

> Smells like a core feature to me.

I'm certainly open to adding more advanced search tabs to the core.

However, this implementation uses the deprecated regexp operand syntax. We should use the new `regexp` filter operator instead if possible.

Best wishes

Jeremy.



Best wishes, Tobias.

--
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 post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

Stephan Hradek

unread,
Jan 1, 2015, 4:06:16 PM1/1/15
to tiddl...@googlegroups.com, jeremy...@gmail.com


Am Mittwoch, 31. Dezember 2014 17:15:05 UTC+1 schrieb Jeremy Ruston:
Hi Tobias

> Smells like a core feature to me.

However, this implementation uses the deprecated regexp operand syntax. We should use the new `regexp` filter operator instead if possible.

It's possible. It's also possible to ignore case:

\define searchInField(field, for, ignore)

<$list filter="[!is[shadow]!is[system]regexp:$field$[$for$$ignore$]]">


<$link><$view field="title"/></$link>

</$list>

\end


<$edit-text tiddler="$:/
temp/advancedsearch" type="search" tag="input"/> <$select field="fieldname" tiddler="$:/temp/advancedsearch">
<option value="
Any">Any</option>
<$list filter="
[!is[shadow]!is[system]fields[]sort[]]" variable="fieldname
">

<option value=<<fieldname>>><<fieldname>></option>
</$list>
</$select> <$checkbox field="ignore" tiddler="$:/temp/advancedsearch" checked="(?i)"> ignore case</$checkbox>

<$reveal state="
$:/temp/advancedsearch" type="nomatch" text="">
<$reveal state="
$:/temp/advancedsearch!!fieldname" type="match" text="Any">
<$list filter="
[!is[shadow]!is[system]fields[]]" variable="fieldname">


Searching in field: <<fieldname>>

<$macrocall $name="
searchInField" field=<<fieldname>> for={{$:/temp/advancedsearch}} ignore={{$:/temp/advancedsearch!!ignore}}/>

</$list>
</$reveal>
<$reveal state="
$:/temp/advancedsearch!!fieldname" type="nomatch" text="Any">


Searching in field: {{$:/temp/advancedsearch!!fieldname}}

<$macrocall $name="searchInField" field={{$:/temp/advancedsearch!!fieldname}} for={{$:/temp/advancedsearch}} ignore={{$:/temp/advancedsearch!!ignore}}/>

</$reveal>

</$reveal>


Jeremy Ruston

unread,
Jan 2, 2015, 5:39:24 AM1/2/15
to Stephan Hradek, TiddlyWiki
It's possible. It's also possible to ignore case:

Great, thank you Stephan. Would anyone like to try their hand at creating a pull request for this? One additional requirement is to use the translation mechanism to make the legend "Searching in field:" be translatable.

Best wishes

Jeremy.



 

\define searchInField(field, for, ignore)

<$list filter="[!is[shadow]!is[system]regexp:$field$[$for$$ignore$]]">

<$link><$view field="title"/></$link>

</$list>

\end


<$edit-text tiddler="$:/
temp/advancedsearch" type="search" tag="input"/> <$select field="fieldname" tiddler="$:/temp/advancedsearch">
<option value="
Any">Any</option>
<$list filter="
[!is[shadow]!is[system]fields[]sort[]]" variable="fieldname
">
<option value=<<fieldname>>><<fieldname>></option>
</$list>
</$select> <$checkbox field="
ignore" tiddler="$:/temp/advancedsearch" checked="(?i)"> ignore case</$checkbox>

<$reveal state="
$:/temp/advancedsearch" type="nomatch" text="">
<$reveal state="
$:/temp/advancedsearch!!fieldname" type="match" text="Any">
<$list filter="
[!is[shadow]!is[system]fields[]]" variable="fieldname">


Searching in field: <<fieldname>>

<$macrocall $name="
searchInField" field=<<fieldname>> for={{$:/temp/advancedsearch}} ignore={{$:/temp/advancedsearch!!ignore}}/>

</$list>
</$reveal>
<$reveal state="
$:/temp/advancedsearch!!fieldname" type="nomatch" text="Any">

Searching in field: {{$:/temp/advancedsearch!!fieldname}}

<$macrocall $name="
searchInField" field={{$:/temp/advancedsearch!!fieldname}} for={{$:/temp/advancedsearch}} ignore={{$:/temp/advancedsearch!!ignore}}/>

</$reveal>

</$reveal>


Tobias Beer

unread,
Jan 3, 2015, 8:59:05 PM1/3/15
to tiddl...@googlegroups.com, jeremy...@gmail.com
Hi Stephan,

we should use the new `regexp` filter operator instead if possible.
 
It's possible. It's also possible to ignore case: 

Nice, I've updated both in my adaptation as well...


Added the checkbox up top, though... not sure.

Best wishes, Tobias. 

Илья Тимонин

unread,
Jan 10, 2016, 4:46:55 AM1/10/16
to tiddl...@googlegroups.com, jeremy...@gmail.com
Hi!

Is there an ability to search through entire tiddlywiki (including tags, titles and fields) in one tab? Can I add this mechanism as default search on sidebar? Can I add field "title" by default to "*any" option in advanced search in fields?



воскресенье, 4 января 2015 г., 4:59:05 UTC+3 пользователь Tobias Beer написал:

David Szego

unread,
Nov 20, 2016, 11:53:18 AM11/20/16
to TiddlyWiki
A million expletives here... WHY hasn't this been pulled into Core yet?!?!?

Thank you thank you thank you, as always, Tobias. You solved a major pain in my tuchus in about 2 minutes of searching.

D.



On Wednesday, 31 December 2014 05:33:46 UTC-5, Tobias Beer wrote:
Hi Stephan,

This is very useful. I slightly modified it and added it here...

stevesuny

unread,
Jul 12, 2017, 1:54:30 PM7/12/17
to TiddlyWiki
Thanks, Tobias! Yet again, search and ye shall find! This is exactly what I was looking for: a quick way to search across field values in tiddlers.

//steve.

Alex

unread,
Oct 1, 2019, 9:26:28 AM10/1/19
to tiddl...@googlegroups.com
If anyone is looking for a solution, here it is:

There is an extrem powerful Update for the "search"-Operator (https://tiddlywiki.com/#search%20Operator) in 5.1.18 which allow to use multiple fields to be passed.

With this new operator it is extremly easy to search in all fields at the default search:

Simply add :* after search-operator in list-widget in $:/core/ui/DefaultSearchResultList:

\define searchResultList()
//<small>{{$:/language/Search/Matches/Title}}</small>//

<$list filter="[!is[system]search:title{$(searchTiddler)$}sort[title]limit[250]]" template="$:/core/ui/ListItemTemplate"/>

//<small>{{$:/language/Search/Matches/All}}</small>//

<$list filter="[!is[system]search:*{$(searchTiddler)$}sort[title]limit[250]]" template="$:/core/ui/ListItemTemplate"/>

\end
<<searchResultList>>

I think this would be very helpful, if this is part of the generic tiddlywiki.

Maybe one could add a settingstiddler to exclude or include some standard-fields like author, text & created.

For me this very simple solution is wonderful and helps a lot creating a people-db based on field-values.

Thanks Jeremy.

Mohammad

unread,
Oct 1, 2019, 3:09:59 PM10/1/19
to TiddlyWiki
Alex,
 This is interesting!
It would be great if the result show not only title but field name!

Also for people like to use your code, explain what is $(searchTiddler)$ and  where you define it!

--Mohammad

TonyM

unread,
Oct 1, 2019, 8:25:38 PM10/1/19
to TiddlyWiki
It is also important to point out you can Actualy include a list of fields to search rather than all. So you could include a keywords and caption field and not others like dates.

Regards
Tony

Alex

unread,
Oct 1, 2019, 8:41:07 PM10/1/19
to TiddlyWiki
@Mohammad:

I think you could change die SearchResult within the tiddler $:/core/ui/ListItemTemplate:

<div class="tc-menu-list-item">
<$link to={{!!title}}>
<$view field="title"/>
</$link>
</div>

Change parameters of link-widget to show the field-name.

$(searchTiddler)$ is a temp-tiddler from the tiddlywiki core. It contains the the link to $:/temp/search (according to $:/core/ui/SideBarSegments/search). To understand the filter you can think of it as the search-term someone entered.


@Tony

Thats right. Even thought about some kind of settings-tiddler to simple change the searched fields.

TonyM

unread,
Oct 1, 2019, 10:23:51 PM10/1/19
to TiddlyWiki
Mohammad,

I would suggest cloning $:/core/ui/ListItemTemplate: then edit it, and add template="newtiddler" to the list if possible.

Regards
Tony

Mohammad

unread,
Oct 1, 2019, 11:47:17 PM10/1/19
to TiddlyWiki
Tony

I got the point!
By the way I think the search in Fields by Tobias Beer is a complete solution of course in TW 5.1.14+

--Mohammad

Mohammad

unread,
Oct 1, 2019, 11:49:24 PM10/1/19
to TiddlyWiki
Thanks Alex,
 Yes, the $:/core/ui/ListItemTemplate should be modified!
By the way it still needs more $list and filter to locate and display the field in which the keyboard is found!

Also, it good to add the minlength of 3 to trigger the search after three characters entered in the search box.


--Mohammad


On Wednesday, October 2, 2019 at 5:53:51 AM UTC+3:30, TonyM wrote:
Reply all
Reply to author
Forward
0 new messages