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


On Wed, May 5, 2021 at 8:53 PM Mohammad Rahmani <[email protected]>
wrote:

> 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
>
>
> On Wed, May 5, 2021 at 8:33 PM Mohammad Rahmani <
> [email protected]> wrote:
>
>> 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
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/CAAV1gMCoV9oLYmVo2dtZwLCnTyBA9EVSO46jX1Bs5h0mn5DoJw%40mail.gmail.com.

Attachment: Google-Like-Search-ii.json
Description: application/json

Reply via email to