KISS Macro to Create a List-Search

Background
The list-search is a macro allows to search in a filtered list of tiddlers through a search box (e.g. text box).

Originally it was developed by Tobias Beer. Later Shiraz from kookma, adopted an improved version of Tobias list-search macro and other users also developed their own version (see for example @DaveGifford list-search macro).

KISS implementation
This is a KISS (keep it simple, stupid) implementation. Thanks to subfilter operator which allows to pass a string variable as filter to it.

\define list-search(filter)
<$edit-text field="search" placeholder="enter keywords or regex pattern to search" size="50"/>

<$set field=search name=term tiddler=<<currentTiddler>> >
<$list filter="[subfilter<__filter__>]" template="$:/core/ui/ListItemTemplate" />
</$set>
\end

Example i

<<list-search "[!is[system]regexp<term>limit[25]]" >>

Example ii

<<list-search "[tag[Learning]search:title<term>]">>

How it works

  • An $edit-text widget gets the search keywords or regex pattern from user
  • The keywords/patterns are stored in search field of current tiddler
  • The $set widget retrieves the user input
  • The $list widget simply uses the filter, dynamically created, and shows the results if any!

Magic

  • The filter is passed in Example i is [!is[system]regexp<term>limit[25]] but the term is not existed at the scripting time, and it will be created at run time. The same is true for Example ii. The subfilter receives the dynamic filter as string variable and runs it!

To give a try

  1. download kiss-macro-list-search.json (932 Bytes)

  2. drag and drop kiss-macro-list-search.json from step 1 into https://tiddlywiki.com

  3. open Example i and Example ii and try to search

References

Update ii: Example ii corrected!

4 Likes

A screenshot of working macro (Example i above)
img_248_msedge

@TiddlyTweeter
Example i lets to play with regex pattern :wink:

@Mohammad: very nice :slight_smile:

It would be perfect, if the search includes the caption field and the output list also show a field/user field - eg. “modified”.
How can that be done?

Always happy to see improvements to list-searches.

Just for accuracy’s sake, I did not create a list-search macro. I have always used Tobias’ macro and have simply created different search filters and different list item templates.

My most creative effort was a file with two list item templates, one closed and one open, and the open one had this content:

<details open><summary><b><$view field="title"/></b> ^^<$link>(open)</$link>^^ <$button class="tc-btn-invisible"><$action-sendmessage $message="tm-new-tiddler" tags={{{ [{!!title}format:titlelist[]] }}}/> ^^{{$:/core/images/new-button}}^^</$button></summary>

<div class="tc-table-of-contents"><span class="blacklinks"><$macrocall $name="toc" tag={{!!title}}>></span></span>

</details>

with a result like this:

In other words, the list search itself displayed details elements, an open to edit button, and a new-here button, and the innards of the details element displayed a toc macro with new buttons for each item in the list.

2 Likes

I’ve never thought about using templates with the list widget. I am quite intrigued by this and am thinking of several uses.

Question - does using a template with the list widget have any performance advantages over formatting the list without a template? What are the pros and cons of using a template with the list widget?

I suspect no, why? because when you don’t give a template the content of the list widget is the template. Consider my most used form of the list widget;

<$list filter="my filter">

</$list>
  • When no template given and content is one blank line
  • How does the second example work, there is no parameter named for the value “Operator”

[Edited] Also how do you use regular expressions? the search is not using :regexp

Technically it always uses a template. The default is $:/core/ui/ListItemTemplate. In Tobias’ version you just replace that with the title of your custom template.

The “Pro” is the added functionality.

Con: I imagine if a template is complex it could slow performance. But the one I showed above did not slow performance that I could see. I don’t think most templates would cause problems for performance.

You can simply use your own template. For example see the template provided by @DaveGifford.
You can change template="$:/core/ui/ListItemTemplate" with the one you like or even add another macro input parameter to pass the name of template.

Hi Tony,

Ah, that is a leftover. I corrected the OP.

See the examples, example i uses a regexp search operator and example ii uses a simple search in title. So actually it is by user to choose what filter pass to macro.

1 Like

Thank you. Beautifully simple, and very useful!

I’m curious about this (and I think Tony was asking the same thing):

What is "Operator" doing there, and how is is supposed to be used? I see no other references.

1 Like

Ah sorry, that is left over from previous work. I corrected the example in the OP.

2 Likes

Thanks @Mohammad and @TW_Tones for the clear explanations. As an intermediate+ experienced user with TiddlyWiki, I still find that there are many things that I should know by now, but don’t. I tend to know a small number of things pretty well, but not so much on the other 75%.

2 Likes

Hi @Mohammad ,

I am using this for a project and cloned so I have four variations (mainly because you have it set up to add the custom template in the macro, which means I need four macros if I have four different templates. This macro is great! Thank you so much for it.

Question: is there a way to have it so searches for question and Question turn up the same results? That is, that one doesn’t have to match the capitalization in order to get all the relevant results?

If you add KISS to TiddlyWiki.com and open example i, you will see “BJTools” as the fourth entry in the list. If you type bjt, BJTools will not come up. So upper and lower case letters are not being considered identical. I am asking if there is a way for them to be considered identical. Thanks!

Hello again Dave,
I the last reply, I explained Shiraz list-search. Here in Example i, I used a search filter like below:

<<list-search "[!is[system]regexp<term>limit[25]]">>

and you know regexp is casesensitive. Use filter like

<<list-search "[!is[system]search<term>limit[25]]">>

This is case-insensitive.

1 Like

Ahhhh ok now I see. Search is not case sensitive, but regexp is. I will switch to search to make it easier for my users! Thanks!

1 Like

For users entering this thread, please note that for the moment, if you want to use KISS for online files, you will need the fix that Eric Schulman provides in this thread

1 Like