Note that this will only work correctly if the values you are searching for do not contain spaces. For example, suppose you want to find “Douglas Adams” (with a space), and you have two tiddlers, one with “Douglas Adams”, and another with “[[James Adams]] [[Douglas Trumbull]]”. If you search using
{{{ [all[tiddlers]search:*[Douglas Adams]] }}}
It will find THREE tiddlers. This is because the search:*[]
filter operator separately matches keywords “Douglas” and “Adams”, but doesn’t recognize the doubled square bracket “list” syntax. It also matches the tiddler in which your search filter syntax occurs. You can account for this by using:
{{{ [all[tiddlers]search:*:literal[Douglas Adams]] -[<currentTiddler>] }}}
which finds fields containing an exact match to the parameter value and ignores the tiddler in which the search filter syntax occurs.
Alternatively, you could use a regexp pattern, like this:
{{{ [all[tiddlers]search:*:regexp[Douglas\s*Adams]] -[<currentTiddler>] }}}
which will match “DouglasAdams” or “Douglas Adams” or even “[[Douglas Adams]]” … but NOT “[[James Adams]] [[Douglas Trumbull]]”.
Of course, this means that you need to have the “\s*” pattern in your search string. But if you are getting the search string from user input (i.e., via an $edit-text
widget), you will probably want to just type “Douglas Adams” (with a regular space character).
Fortunately, this can be handled with a little “fixup” code to replace the spaces with \s*
. Something like this:
<$edit-text field=find/>
<$let pattern={{{ [{!!find}search-replace:g[ ],[\s*]] }}}>
<%if [<pattern>!match[]] %>
{{{ [all[tiddlers]search:*:regexp<pattern>] -[<currentTiddler>] }}}
<%endif%>
Notes:
- The
<%if%>...<%endif%>
conditional syntax prevents the search from finding ALL tiddlers when no input has been entered into the $edit-text
widget.
- While the search filter syntax doesn’t contain the literal text you are searching for, the currentTiddler still has a field named
find
that contains that input text, so you still need !match<currentTiddler>
to prevents the search from finding that tiddler.
enjoy,
-e