Search box using symbol and search prefix

159 views
Skip to first unread message

Mohammad Rahmani

unread,
May 5, 2021, 12:03:32 PM5/5/21
to tiddl...@googlegroups.com
Is there any plugin or wikitext to let search using search prefix and symbols?

I mean like Google or GitHub using something like below

title:myTiddler
keywords:myKeywords
tags:myTerm

Here title and keywords and tags are search prefixes! In Tiddlywiki they are fields
The symbol is colon(:)

So a prefix:term is the format to use a simple search box but do a more precise search!


Best wishes
Mohammad

Mohammad Rahmani

unread,
May 5, 2021, 12:23:56 PM5/5/21
to tiddl...@googlegroups.com
This is a partial solution!
  1. In tiddlywiki.com create a new tiddler and paste the below wikitext
  2. Save and enter in the search box a prefix:term  like title:operator or tags:learnings

\define tidTemp() xx$:/temp/kookma/search
\define doSearch(field:"", term:"")
<$list filter="[all[tiddlers]!is[system]search:$field$:literal[$term$]]">

</$list>
\end


<$edit-text tiddler=<<tidTemp>> field=text default="" tag=input/>

<small>''Search for'': {{xx$:/temp/kookma/search}}</small>

<!-- parse and search-->
<$list filter="[<tidTemp>get[text]enlist-input[]search:title[:]]">
<$vars search-prefix={{{[<currentTiddler>split[:]first[]]}}}
       search-term={{{[<currentTiddler>split[:]last[]]}}} >
<$list filter="[<search-prefix>!is[blank]] [<search-term>!is[blank]] +[count[]match[2]]" variable=null>
<$macrocall $name=doSearch field=<<search-prefix>> term=<<search-term>> />
</$list>
</$vars>

</$list> 



Please comment to improve! If there is a previous solution please let me know!
I like to parse the input for several prefix:term like Google!


Best wishes
Mohammad

Mohammad Rahmani

unread,
May 5, 2021, 12:25:20 PM5/5/21
to tiddl...@googlegroups.com
Note: in prefix:term space is not allowed!

Best wishes
Mohammad

Stobot

unread,
May 5, 2021, 1:46:22 PM5/5/21
to TiddlyWiki
I've thought about the concept myself a lot over the years, and ended up deciding that if I was going to go that far, I might as well just use filter notation. So rather than do something special for tags:myTerm I'd just do [tag[myTerm]]. Now you can't do that in the normal, main search box, but I have a sidebar tab with kind of a persistent search area and I use prefix filtering to see what kind of results I want. 
* If I want a "system" based search I start the search string with "$"
* If I want a "shadow" based search, I start it with "!"
* If I want a "filter" based search, I start it with "["
* If it has none of those, I just have it return regular results

Just for reference since you asked for wikitext, I have a normal <$edit..> widget for the search box going to $:/temp/mysearch, and then down below is the parsing. 

<$vars regfilter="^\[" regsystem="^\$" regshadow="^\!" mysearch={{$:/temp/mysearch}} mysearchelse={{{ [{$:/temp/mysearch}trim[$]trim[!]] }}}>

<!-- Filter type search -->
<$list filter="[<mysearch>regexp<regfilter>]">
    <$list filter="[<mysearch>minlength[2]]" emptyMessage="">        

        //Filter results://<br>
        <$list filter=<<mysearch>> emptyMessage="(no filter matches)">
            <$link>{{!!title}}</$link><br>
        </$list><hr>

    </$list>
</$list>

<!-- System type search -->
<$list filter="[<mysearch>regexp<regsystem>]">
    <$list filter="[<mysearchelse>minlength[2]]" emptyMessage="">        

        //Title contains://<br>
        <$list filter="[is[system]search:title<mysearchelse>]" emptyMessage="(no title matches)">
            <$link to={{!!title}}><$text text={{!!title}}/></$link><br>
        </$list><hr>

        //Text contains://<br>
        <$list filter="[is[system]search:text<mysearchelse>]" emptyMessage="(no text matches)">
            <$link to={{!!title}}><$text text={{!!title}}/></$link><br>
        </$list><hr>

    </$list>
</$list>

<!-- Shadow type search -->
<$list filter="[<mysearch>regexp<regshadow>]">
    <$list filter="[<mysearchelse>minlength[2]]" emptyMessage="">        

        //Title contains://<br>
        <$list filter="[all[shadows]search:title<mysearchelse>]" emptyMessage="(no title matches)">
            <$link to={{!!title}}><$text text={{!!title}}/></$link><br>
        </$list><hr>

        //Text contains://<br>
        <$list filter="[all[shadows]search:text<mysearchelse>]" emptyMessage="(no text matches)">
            <$link to={{!!title}}><$text text={{!!title}}/></$link><br>
        </$list><hr>

    </$list>
</$list>

<!-- Standard type search -->
<$list filter="[{$:/temp/mysearch}!regexp<regfilter>!regexp<regsystem>!regexp<regshadow>!regexp[^\+]]">
    <$list filter="[{$:/temp/mysearch}minlength[2]]" emptyMessage="">        

        //Title starts with://<br>
        <$list filter=<<PrefixFilter>> emptyMessage="(no prefix matches)">
            <$link>{{!!title}}</$link><br>
        </$list><hr>

        //Title contains://<br>
        <$list filter=<<TitleFilter>> emptyMessage="(no title matches)">
            <$link>{{!!title}}</$link><br>
        </$list><hr>

        //Text contains://<br>
        <$list filter=<<TextFilter>> emptyMessage="(no text matches)">
            <$link>{{!!title}}</$link><br>
        </$list>

    </$list>
</$list>

Mohammad Rahmani

unread,
May 5, 2021, 2:08:05 PM5/5/21
to tiddl...@googlegroups.com
Lovely! very handy!





On Wed, May 5, 2021 at 10:16 PM Stobot <sto...@gmail.com> wrote:
I've thought about the concept myself a lot over the years, and ended up deciding that if I was going to go that far, I might as well just use filter notation. So rather than do something special for tags:myTerm I'd just do [tag[myTerm]].

Yes, that's quite true, I always use $:/AdvancedSearch and it is very powerful! Just one point if you distribute your wiki to people with no or little TW knowledge the the Google search format is simple and more people know that!



 
Now you can't do that in the normal, main search box, but I have a sidebar tab with kind of a persistent search area and I use prefix filtering to see what kind of results I want. 
* If I want a "system" based search I start the search string with "$"
* If I want a "shadow" based search, I start it with "!"
* If I want a "filter" based search, I start it with "["
* If it has none of those, I just have it return regular results


very clever!

Tested on tiddlywiki.com works like a charm!
Thank you

 
--
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/dfe1c5b6-6a30-46fe-96ce-9ad5b6a8e58dn%40googlegroups.com.

Mohammad Rahmani

unread,
May 5, 2021, 5:34:33 PM5/5/21
to tiddl...@googlegroups.com
Version II

This is a more polished version of 'prefix:term' or Google like search box.

What is new:
  • search like created:2020 title:operator which returns results to meet both criteria
  • search filter is displayed
  • search tips can be displayed on demand using details element
  • search limits and minlength has their own variable to be set easily

Please give your comments to improve the code. For example improve the parser for a simpler
more semantic script! 

To give a try drag and drop the attached file into tiddlywiki.com and see how it works!

\define searchTips()
<details>
<summary><small>Search tips</small></summary>
<ul>
<li>use `prefix:term` to search in field=prefix for term</li>
<li>use `title:test` will search in `title` field for term `test`</li>
<li>no space between colon(`:`) and words allowed</li>
<li>using two or more `prefix:term` pairs returns result to meet both/all criteria</li>
</ul>
</details>
\end


\define tidTemp() xx2$:/temp/kookma/search
\define minlength-searchterm() 2
\define limit-output() 250
\define searchFilter() [all[tiddlers]!is[system]] $(sterms)$ +[limit[$(limit-output)$]]
\define populates()    +[search:$(search-prefix)$:literal[$(search-term)$]]

\define parser()
<!-- parse the search term-->

<$list filter="[<tidTemp>get[text]enlist-input[]search:title[:]]">
<$vars search-prefix={{{[<currentTiddler>split[:]!is[blank]first[]]}}}
       search-term={{{[<currentTiddler>split[:]!is[blank]last[]]}}} >
<$list filter="[<search-prefix>!is[blank]] [<search-term>minlength[$(minlength-searchterm)$]] +[count[]match[2]]" variable=null>
<$text text=<<populates>> />
</$list>
</$vars>
</$list>
\end


<!-- styles -->
<style>.wd{width:50%;}</style>

<$edit-text tiddler=<<tidTemp>> field=text default="" tag=input class=wd/>
<<searchTips>><!-- display help on demand -->

<$wikify name=sterms text=<<parser>>  ><!-- parse and wikify the search terms -->
<small>''Search terms'': <$text text=<<sterms>> /></small>

<$list filter="[<sterms>trim[]!is[blank]]" variable=null> <!-- check for correct input, do not trigger search on empty input -->
<$list filter=<<searchFilter>> >

</$list>
</$list>
</$wikify>


The temp tiddler has a name xx2$ for debugging purposes! change as you like!



Best wishes
Mohammad

Google-Like-Search-ii.json

Mohammad Rahmani

unread,
May 6, 2021, 6:34:57 PM5/6/21
to tiddl...@googlegroups.com
Version V

Search Using Prefixes - iv supports operators
Use + to include and - to exclude
This version also support single term and mixed form e.g (title:HelloThere  novel)



    • use prefix:term to search in field=prefix for term
    • use title:test will search in title field for term test
    • no space between colon(:) and words allowed
    • using two or more prefix:term pairs returns result to meet both/all criteria
    • using - operator exlcudes results, e.g -title:term excludes results with term in the title
    • using + operator includes results, e.g +title:term includes results with term in the title. This is the default behaviour
    • search minimum length: 3, search only triggers if term length is greater than this value
    • maximum number of output:

    To give a try download,  drag and drop to tiddlywiki.com



    Best wishes
    Mohammad

    Search Using Prefixes - v working case 2.json
    Reply all
    Reply to author
    Forward
    0 new messages