How to? Build a custom search box

349 views
Skip to first unread message

Surya

unread,
Sep 22, 2018, 3:35:31 PM9/22/18
to TiddlyWiki
Hello all dear TW-people,

I fear, it's a big thing what I'd like to have, but I'll try it...
I already tried to solve it by myself, but with that I broke my whole search-functionality, so I won't try it anymore by myself... ;-)

What I want:
I'd like to have two different search boxes, which I want to hide or to show.
For my visitors I want the search-box "visitors-search", they shouldn't see my own search-box.
For myself I want my own search-box, I don't want to see the "visitors-search".

(With other buttons I already show/hide them with for example <$checkbox tiddler="$:/core/ui/SideBar/More" tag="$:/tags/SideBar"> Show Tab ▼ "More" in SideBar</$checkbox>)


In the "visitors-search": Don't show tiddlers with Tag A and Tag B.
For example, if they search for "Body", it should show only the tiddlers with "Body" in the title, but not if they are tagged with Tag A or Tag B.
Then, the result should show the list of that tiddlers and count them.

For myself I have already a good search.


Do you understand, what I mean??
Thanks in advance for your help!! Surya

TonyM

unread,
Sep 22, 2018, 7:20:18 PM9/22/18
to TiddlyWiki
Surya,

In a recent thread I shared the simple code for a custom search, basicaly an edit text widget which feeds a list filter using the search opperator. Thus you can add whatever selection criteria you want before the search operator. This method is very simple but does not provide the search results dropdown you want.

Adding things to the sidebar (not tabs) will be driven by a system tag in the next release.

To get a replica of the current search I would review the existing one to see if I could add additional filters and clone and edit the existing one, the edit another system tiddler to display it in the sidebar. Or wait for the next release.

I plan to make a custom search soon as a goto (TWC) which only searches the titles of selected tiddlers soon.

Regards
Tony

Surya

unread,
Sep 22, 2018, 8:38:00 PM9/22/18
to TiddlyWiki
Hi Tony :-)

So, it is not yet possible?
Could you please tell me, when it will be possible?
Thank you!

To get a replica of the current search I would review the existing one to see if I could add additional filters and clone and edit the existing one, the edit another system tiddler to display it in the sidebar.
Yes, that I tried- and the wohle search functionality got broken... Good luck, that there are the backups on tiddlyspot, so I got it back again :-)

Surya

TonyM

unread,
Sep 22, 2018, 10:13:16 PM9/22/18
to TiddlyWiki
Surya,

No it is all possible to do it now, just a little more complext and you need to modify a shadow tiddler to get it in the sidebar (not tabs).

Regards
Tony

Surya

unread,
Sep 22, 2018, 10:56:46 PM9/22/18
to TiddlyWiki
I made it :-)))

With this (searching for your last threads, finding this and edited it for my needs):
<$edit-text tiddler="$:/config/References/searchstrings" field=all-reference-search placeholder="Type your Search" tag=input/><br/><br/>
<summary>Suchergebnis</summary>

<$list filter="[!is[system]search:title{$:/config/References/searchstrings!!all-reference-search}] +[!tag[>]search:title{$:/config/References/searchstrings!!all-reference-search}] +[!tag[A]search:title{$:/config/References/searchstrings!!all-reference-search}] +[!tag[B]" emptyMessage="None">
<div style="margin-left:1em;">
<li><$link><<currentTiddler>></$link></li></div>
</$list>


The only thing is now, that it finds all tiddlers (except the ones with the unwanted tags), when the search-box is empty.
How can I edit it, so that it doesn't find anything, when the search-box is empty?

Thanks a lot, Tony!!!
Surya

TonyM

unread,
Sep 22, 2018, 11:33:33 PM9/22/18
to TiddlyWiki
Yourve missed the <details> I had to hide the result until selected but you could wrap the search in another list that tests if the search string is empty or shorter than 3 characters.

I'm off my desktop, feeling a little ill so cant lookup the code patterns.

I will share later when possible

Regards
Tony

Surya

unread,
Sep 23, 2018, 2:39:21 PM9/23/18
to TiddlyWiki
Hi Tony,

hope, you get well...

Well, I haven't forgotten <details>, but I deleted that, because I wanted, that the results are shown immediately without anymore click :-)

Hmmm, I have an idea how to write the other list for testing if search string is empty.
But I am in fear, that I break again the whole search functionality with testing such a list.
So I would be really happy, if you could tell me how to write it.
But that isn't urgent- so at first get well please :-)

Surya

TonyM

unread,
Sep 23, 2018, 7:47:43 PM9/23/18
to TiddlyWiki
Surya,

The <summary>blah blah</summary> is part of the details so perhaps remove that

On tiddlywiki.com I see 

$:/config/Search/MinLength is in use, searching with the advanced search I see it is used in 


Opening 
$:/core/ui/AdvancedSearch/Standard

We see it is used as follows "[{$:/temp/advancedsearch}minlength{$:/config/Search/MinLength}limit[1]]" 

Which is already set to three so lets use that

In this case "[{$:/config/References/searchstrings!!all-reference-search}minlength{$:/config/Search/MinLength}limit[1]]" 

Please note: In my example I was searching for Reference Items so I used $:/config/References/searchstrings and because I wanted more than one I used the field !!all-reference-search
But you can change this to $:/config/mytiddler and not use the field if you want, this will use the text field instead.

The above filter is limited to one, so if there is any tiddler with that minlength it will show

You may combine this with your existing list filter but given its current complexity wrap your existing list with another with this filter.

The inner list will only be operated if this condition is true. ie 

Please not I have not tested this yet myself but I am confident it should work.

Regards
Tony

Surya

unread,
Sep 24, 2018, 3:43:32 PM9/24/18
to TiddlyWiki
Hey Tony :-)))

It works!! :-)) THANKS A LOT!!

Now it is like this:
<$edit-text tiddler="$:/config/References/
searchstrings" field=all-reference-search placeholder="Type your Search" tag=input/><br/><br/>
Search result:

<$list filter="[{$:/config/References/searchstrings!!all-reference-search}minlength{$:/config/Search/MinLength}limit[1]]" emptyMessage="""<div class="tc-search-results">{{$:/language/Search/Search/TooShort}}</div>""" variable="listItem">

<$list filter="[!is[system]search:title{$:/config/References/searchstrings!!all-reference-search}] +[!tag[>]search:title{$:/config/References/searchstrings!!all-reference-search}] +[!tag[A]search:title{$:/config/References/searchstrings!!all-reference-search}] +[!tag[B]" emptyMessage="None">
<div style="margin-left:1em;">
<li><$link><<currentTiddler>></$link></li></div>
</$list>


Fantastic! Surya
and I am happy, that it is a little bit similar to my own idea :-)

TonyM

unread,
Sep 24, 2018, 8:57:50 PM9/24/18
to TiddlyWiki
Great to hear and Good work, often a learning experience is better than an answer.

Regards
Tony

B Gupta

unread,
Aug 29, 2023, 2:19:12 AM8/29/23
to TiddlyWiki
As a relatively new TiddlyWiki user, I have been experimenting with features and trying new ideas. After lots of searching to create a custom search box, I came across this thread. While it is five years old, the approach and ideas discussed here are still valid! I tweaked it to create my custom search box in a tiddler running on Tiddlywiki 5.3.1. You can find it here: https://bpg-scripts.tiddlyhost.com/#Custom%20search%20box%20embedded%20in%20a%20tiddler

Jan

unread,
Aug 30, 2023, 1:55:03 AM8/30/23
to TiddlyWiki
Hi, Mr Gupta,
I want to invite you to the Tiddlywiki community on discourse, because most of the discussions happen there and do not fill your postbox : I also stumbled upon your post there https://talk.tiddlywiki.org/t/tw5-re-how-to-build-a-custom-search-box/7917
One tiny tip: You could replace the text you put into each Tiddler with one single viewtemplate.
Reply all
Reply to author
Forward
0 new messages