Search, like many other stuff in TW5, is essentially produced by list 
widget with appropriate filter parameter. 

Add the following code to a tiddler. 

<$edit-text tiddler="$:/temp/mysearch" tag="input" default="Search"/>
>

Essentially it creates a textbox where the typed content is stored in the 
tiddler "$:/temp/mysearch".  To understand the rest of the options, refer 
https://tiddlywiki.com/#EditTextWidget. 

Now we got to create the results.  Add the following code wherever you the 
want the search results to appear (it can be in the same tiddler as the 
text box or anywhere else). 

<$list filter="[search{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
> <$link><<currentTiddler>></$link><br>
> </$list>
>


Now remember,  this is the least minimum code required to produce search 
results. As you can see,  the search results include both standard tiddlers 
and system tiddlers. Now we tweak according to our wishes.  We do not want 
system tiddlers in our results,  so we use filter like this

<$list filter="[!is[system]search{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
> <$link><<currentTiddler>></$link><br>
> </$list>
>

Or, we want to search in system tiddlers only,  so we go like 

<$list filter="[is[system]search{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
> <$link><<currentTiddler>></$link><br>
> </$list>
>

You can customise it further by specifying which fields to search in, what 
kind of tiddlers to search in and so on. Refer: 
https://tiddlywiki.com/#Filter%20Operators.


Now, you can add buttons like "clear the searchbar". "open the advanced 
search" etc if you want. The snippet is as follows.

<$reveal state="$:/temp/mysearch" type="nomatch" text="">
>
> <$button class="tc-btn-invisible" tooltip="Clear searchbar">
> <$action-setfield $tiddler="$:/temp/mysearch" text=""/>
> {{$:/core/images/close-button}}
> </$button>
>
> <$button class="tc-btn-invisible" tooltip="Advanced Search">
> <$action-setfield $tiddler="$:/temp/advancedsearch" 
> text={{$:/temp/mysearch}}/>
> <$action-setfield $tiddler="$:/temp/mysearch" text=""/>
> <$action-navigate $to="$:/AdvancedSearch"/>
> {{$:/core/images/advanced-search-button}}
> </$button>
>
> </$reveal>
>


Another customisation I personally like is showing search results only 
after you finish typing and hit enter key. Here is the code for that:

\define enterthesearch()
> <$action-setfield $tiddler="$:/temp/mysearch" text={{$:/temp/mysearch1}}/>
> <$action-setfield $tiddler="$:/temp/mysearch1" text=""/>
> \end
>
>
> <$keyboard key="enter" actions="enterthesearch">
> <$edit-text tiddler="$:/temp/mysearch1" tag="input" default="Search"/>
> </$keyboard>
>
>
> <$list filter="[!is[system]search{$:/temp/mysearch}] 
> -[[$:/temp/mysearch]]">
> <$link><<currentTiddler>></$link><br>
> </$list>
>



Now finally coming to your request of closing the tiddlers whenever you 
click on a link. As a matter of fact you can do any number of actions when 
you click on a link. Just add what you want to do in the macro definition 
as given below.

\define dowhateveryouwant()
> <$action-navigate $to=<<navigateTo>>/>
> <$action-sendmessage $message="tm-close-tiddler"/>
> <$action-setfield $tiddler="$:/SiteTitle" $value=<<navigateTo>>/>
> \end
>
> <$edit-text tiddler="$:/temp/mysearch" tag="input" default="Search"/>
>
> <$linkcatcher actions=<<dowhateveryouwant>>>
> <$list filter="[!is[system]search{$:/temp/mysearch}minlength[5]] 
> -[[$:/temp/mysearch]]">
> <$link><<currentTiddler>></$link><br>
> </$list>
> </$linkcatcher>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/6f0a558c-fd05-4861-af69-ef17067796d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to