How can I change the default search to exact search?

59 views
Skip to first unread message

Mostafa Hussein Omar

unread,
Jul 25, 2020, 2:52:05 PM7/25/20
to tiddl...@googlegroups.com
I searched this group and I found an answer to how to search for an
exact sentence in a tiddlywiki:

[!is[system]regexp:text[Hello World]]

Now I would like either to have this as the default behaviour of the
search box or to create a tiddler that has a search field that will do
the exact search without asking the user to enter the above syntax
(which is a little unintuitive.

Thanks in advance.

Mostafa

Eric Shulman

unread,
Jul 25, 2020, 4:39:55 PM7/25/20
to TiddlyWiki
On Saturday, July 25, 2020 at 11:52:05 AM UTC-7, Mostafa Hussein Omar wrote:
I searched this group and I found an answer to how to search for an
exact sentence in a tiddlywiki:
   [!is[system]regexp:text[Hello World]]
Now I would like either to have this as the default behaviour of the
search box or to create a tiddler that has a search field that will do
the exact search without asking the user to enter the above syntax

First, I suggest you check my PowerSeach "filter generator" tool, here:


It gives you controls to select many different filter options and construct
the corresponding filter syntax "on the fly".  

This can help you experiment with filtering in general, and can often
help you figure out your desired search syntax without a lot of typing.

For your requested use-case, I suggest using:

[!is[system]search:text:literal[test]sort[title]]

Note the use of "search:text:literal[...]" rather than "regexp:text[...]".
This is because the regexp[...] filter doesn't do an *exact* text search.
Rather, it does search for a text *pattern*, using "regular expression" syntax

In any case, here's a little bit of wikitext "code" that gives you
a custom interface using the above filter syntax:

Search tiddler text for:
<$edit-text tiddler="$:/temp/mysearch" tag="input" size="30" default="" placeholder="enter search text" />

<$reveal state="$:/temp/mysearch" type="nomatch" text="">
<$count filter="[!is[system]search:text:literal{$:/temp/mysearch}sort[title]]" /> matches:<br>
<$list filter="[!is[system]search:text:literal{$:/temp/mysearch}sort[title]]">
   
<$link /><br>
</$list>
</
$reveal>

Just copy/paste the above into a tiddler and you'll be all set.

Notes:
1) $edit-text gets your input and saves it in a "temp" tiddler ($:/temp/mysearch)
2) $reveal prevents any display when the input is blank (otherwise, you would see ALL tiddlers by default!)
3) $count shows the number of matches found
4) $list actually does the search, looping over each matching result
5) $link shows a link to each tiddler that was found

...and, if you want to put this interface into the sidebar tabs:
* add a tag "$:/tags/SideBar"
* add a caption field, e.g., "My Search"

Let me know how it goes...

enjoy,
-e

Mostafa Hussein Omar

unread,
Jul 25, 2020, 5:13:42 PM7/25/20
to tiddl...@googlegroups.com
Thank you very much Eric. This worked like a charm and many thanks for
the Notes section. Now, I have a better understanding of how search
works on TiddlyWiki.

Best,

M.
> --
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/5d3d37d1-c04c-4e21-a9c0-d315795d95dbo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages