search TW5 tiddlers body for exact phrase

595 views
Skip to first unread message

John

unread,
Dec 9, 2017, 10:06:51 AM12/9/17
to TiddlyWiki
When I search in TW5 with a phrase, I get all the tidders which have a word or more of the phrase in any sequence in the title or the body. 

Is there an option or plugin to search only for the exact phrase in the title or the body?

Eric Shulman

unread,
Dec 9, 2017, 10:55:17 AM12/9/17
to tiddl...@googlegroups.com
On Saturday, December 9, 2017 at 7:06:51 AM UTC-8, John wrote:
When I search in TW5 with a phrase, I get all the tidders which have a word or more of the phrase in any sequence in the title or the body. 

Is there an option or plugin to search only for the exact phrase in the title or the body?

You can use the [regexp[...]] filter operator to search for exact phrase matches including spaces.

1) Open the $:/AdvancedSearch panel (click the magnifying glass icon next to the regular sidebar search input field)
2) In $:/AdvancedSearch, switch to the "Filter" tab
3a) To search titles, enter your search syntax like this:
   [regexp[your phrase here]]
3b) To search tiddler text, enter your search like this:
   [regexp:text[your phrase here]]

Notes:
* Because the syntax uses square brackets, you cannot search for text that includes square brackets.
* If you want to search both title AND text fields at the same time, you can combine the filters in a sequence, separated by a space, like this:
   [regexp[your phrase here]] [regexp:text[your phrase here]]
* If you don't want to use the $:/AdvancedSearch interface, you can create your own custom interface by putting the following syntax into a tiddler you create:

<$edit-text tiddler="$:/temp/mysearch" tag="input" default=""/><br>
<$reveal state="$:/temp/mysearch" type="nomatch" text="">
<
<list-links "[regexp{$:/temp/mysearch}] [regexp:text{$:/temp/mysearch}] -[title[$:/temp/mysearch]]">>
</$reveal>

* The $edit-text widget stores your search input in $:/temp/mysearch (you can use any tiddler name you like, but something starting with "$:/temp/..." is recommended to avoid cluttering up your regular list of tiddlers)
* The $reveal widget prevents listing ALL tiddlers when the search input is blank.
* The <<list-links>> macro shows a bullet list using the combined title/text search filter, and also automatically excludes the temporary tiddler that holds your search input text.
* Because the custom search uses a separate tiddler to store the search text, you CAN search for text containing square brackets, as it avoids conflicting with the surrounding filter syntax.
* If you add the tag "$:/tags/SideBar" to your custom tiddler, it will appear as an extra tab in the sidebar, allowing you to quickly invoke the custom search at any time.

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)
InsideTiddlyWiki: The Missing Manuals

RickL

unread,
Dec 9, 2017, 11:58:32 AM12/9/17
to TiddlyWiki
I have had this same question for quite a while.  Your answer helps but still does not help if the phrase is buried deep in a long tiddler.  Any way to highlight the search results?

Thanks

Diego Mesa

unread,
Dec 9, 2017, 1:42:34 PM12/9/17
to TiddlyWiki
Eric,

Your answers are always thorough and well explained.They are an inspiration. Thank you!! 

John

unread,
Dec 9, 2017, 8:49:58 PM12/9/17
to TiddlyWiki
Thank you Eric for your comprehensive answer.

I have three more questions while I have your attention: 

1- How to force the custom search to ignore case? 

I can do this by typing (?i)(Some Example) in the input box and it works.
I want to put it in the custom search tiddler code. I tried all combinations of brackets around $:/temp/mysearch but nothing worked.

2- How to replace the standard search with the new custom search? 

3- In classic TW, I used to search long tiddlers by pressing ctl-F in the browser window. With TW5 under NW, is there a way to have a "find" function similar to ctl-F of the browser?

Thank you

Eric Shulman

unread,
Dec 9, 2017, 10:57:50 PM12/9/17
to TiddlyWiki
On Saturday, December 9, 2017 at 5:49:58 PM UTC-8, John wrote:
Thank you Eric for your comprehensive answer.
I have three more questions while I have your attention: 

1- How to force the custom search to ignore case? 
I can do this by typing (?i)(Some Example) in the input box and it works.
I want to put it in the custom search tiddler code. I tried all combinations of brackets around $:/temp/mysearch but nothing worked.

This is a bit more complex... but only a little.  The trick is to define a macro (e.g., "makefilter") that assembles the complete filter syntax using a variable, like this:

\define makefilter() [regexp[(?i)$(pattern)$]] [regexp:text[(?i)$(pattern)$]] -[title[$:/temp/mysearch]]


<$edit-text tiddler="$:/temp/mysearch" tag="input" default=""/><br>
<$reveal state="$:/temp/mysearch" type="nomatch" text="">
<$vars pattern={{$:/temp/mysearch}}>
<$count filter=<<makefilter>>/> matches:<br>
<$macrocall $name="list-links" filter=<<makefilter>>/
>
</$vars>
</
$reveal>

* The "makefilter()" macro uses a variable named "pattern" that is defined outside the macro itself
* The $vars widget retrieves the value stored in $:/temp/mysearch and sets the "pattern" variable, which surrounds the call to the list-links macro
* You can't use a variable reference as a parameter in the <<list-links ...>> macro syntax, so we use the underlying <$macrocall> widget syntax instead
* Note: I added a bit of extra output using the <$count> widget to show the number of matching results
 
2- How to replace the standard search with the new custom search? 

The standard search interface is defined within the $:/core/ui/SideBarLists shadow tiddler, which also defines the output of the tabbed lists below the search.  To use your custom search, you can replace most of the content in $:/core/ui/SideBarLists, like this:

<div class="tc-sidebar-lists">
{{MySearch}}
<$macrocall $name="tabs" tabsList="[all[shadows+tiddlers]tag[$:/tags/SideBar]!has[draft.of]]" default={{$:/config/DefaultSidebarTab}} state="$:/state/tab/sidebar" />
</div>

To make the custom search look nice in the sidebar, you can also add some styling to the MySearch definition by surrounding the $macrocall within a <div>...</div> block, like this:

<div class="tc-block-dropdown tc-search-drop-down">
<$macrocall $name="list-links" filter=<
<makefilter>>>
</div>

* The <div> uses the same class definitions ("tc-block-dropdown tc-search-drop-down") as the standard search results.  This makes the custom search results "float" on top of the sidebar lists, and gives it a nice surrounding box with rounded corners and drop shadow.
 
3- In classic TW, I used to search long tiddlers by pressing ctl-F in the browser window. With TW5 under NW, is there a way to have a "find" function similar to ctl-F of the browser?

I just use the browser's ctrl-F function, the same way as in TWClassic.

John

unread,
Dec 10, 2017, 1:00:23 AM12/10/17
to TiddlyWiki
Thank you very much Eric. I really appreciate your help.  

coda coder

unread,
Dec 11, 2017, 10:25:08 AM12/11/17
to TiddlyWiki


On Saturday, December 9, 2017 at 7:49:58 PM UTC-6, John wrote:
3- In classic TW, I used to search long tiddlers by pressing ctl-F in the browser window. With TW5 under NW, is there a way to have a "find" function similar to ctl-F of the browser?

Sorry to point this out, but Ctrl-F (like a back button, bookmarks and anything else you normally access from a menu) are "browser features".  NW is not a browser.  So Ctrl-F et al do not exist unless they are re-implemented by the underlying "page" (read: a ton of work to code and support).

Coda

RickL

unread,
Dec 26, 2017, 4:12:50 PM12/26/17
to TiddlyWiki
I must not have  been clear in my question....so I will try again...How can one find a word in a TiddlyWiki file by a simple search if it is buried in a long tiddler?

Thanks

BJ

unread,
Dec 27, 2017, 4:55:40 AM12/27/17
to TiddlyWiki
take at look at Danielo's plugin:

http://contextplugin.tiddlyspot.com/

all the best
BJ

RickL

unread,
Dec 27, 2017, 10:06:48 AM12/27/17
to TiddlyWiki
Thanks for your reply and your help.  This plugin is exactly what I needed, and should be part of the default file in my opinion.
Reply all
Reply to author
Forward
0 new messages