Search in datatiddler

129 views
Skip to first unread message

Magnus

unread,
Sep 15, 2018, 8:13:20 PM9/15/18
to TiddlyWiki
Hi, I'm trying to make a custom search from two data-tiddlers. I want to limit the search and only show the results that match the search field but can't make it work. Any help appreciated :)
/Magnus

<table>
  <tr>
    <td>Limit to: <$edit-text tiddler="$:/state/table" tag="input" default="" placeholder={{$:/language/Manager/Controls/Search/Placeholder}}/>
    </td>
  </tr>
  <tr>
    <td><$radio  tiddler="$:/state/table" field="selection" value="abbreviations"> Abbreviations</$radio>
<$radio  tiddler="$:/state/table" field="selection" value="auctor"> Auctor</$radio>

<$reveal state="$:/state/table!!selection" type="match" text="abbreviations">
   <br><br>
    <table class="nolines">
          <$list filter="[[$:/_dictionary/abbreviation]] [[$:/_dictionary/pronunciation]] +[indexes[]]">
      <tr>
          <td><<currentTiddler>></td>
          <td><$view tiddler="$:/_dictionary/abbreviation" index=<<currentTiddler>>/></td>
          <td><$view tiddler="$:/_dictionary/pronunciation" index=<<currentTiddler>>/></td>
        </tr>
        </$list>
      </table>
</$reveal>
<$reveal state="$:/state/table!!selection" type="match" text="auctor">
   <br><br>
      <$set name="data" value="$:/_dictionary/auctor">
      <$list filter="[<data>indexes[]sort[title]]">

      ;{{!!title}}
      :<$transclude tiddler=<<data>> index=<<currentTiddler>>/>
      </$list>
      </$set>
</$reveal>
    </td>
  </tr>
</table>

Mark S.

unread,
Sep 15, 2018, 9:43:51 PM9/15/18
to TiddlyWiki
For "auctor", I changed the list filter to:

    <$list filter="[<data>indexes[]prefix{$:/state/table}sort[title]]">

This seemed to work BUT you have to initialize the state tiddler by filling the edit field several times before the list stops throwing errors. After that it seems to work fine. I feel that this may be a subtle bug where the {...} transclusion is returning a null internally rather than an empty string.

Since it throws errors -- be sure to make backups first!

Good luck
-- Mark

Magnus

unread,
Sep 15, 2018, 11:08:31 PM9/15/18
to TiddlyWiki
Thank you, I will try that :)

Magnus

unread,
Sep 15, 2018, 11:30:20 PM9/15/18
to TiddlyWiki
I wrote it like this and I think it works:

<$list filter="[<data>indexes[]search{$:/state/table}sort[title]]">

:)

Magnus

unread,
Sep 16, 2018, 10:35:45 PM9/16/18
to TiddlyWiki
This does work but if noting is written in search input-field all content in data-tiddler shows, making a very long list. I tried adding a emptyMessage="" to the list filter but that don't work. Any other way it's possible to hide the unfiltered content?

Mark S.

unread,
Sep 16, 2018, 11:55:05 PM9/16/18
to TiddlyWiki
It appears that the [{$:/state/table}]  returns an invisible "something" that the filter sees as "non-empty". This makes my solution rather convoluted. For the 2nd part I came up with:

<$set filter="[{$:/state/table}addprefix[X]addsuffix[X]!prefix[XX]] [title[XEMPTYX]] OTHER +[nth[1]removeprefix[X]removesuffix[X]]" name="searchme"  >

<$reveal state="$:/state/table!!selection" type="match" text="auctor">
   
<br><br>

      <$set name="data" value="$:/_dictionary/auctor">
Searching for: ::<<searchme>>::<br/>
      <$list filter="[
<data>indexes[]prefix<searchme>sort[title]]">
      ;{{!!title}}
      :<$transclude tiddler=<
<data>> index=<<currentTiddler>>/>
      </$list>
      </$set>
</$reveal>
</$set>

Note that the set widget uses a filter to take the input field, append and prepend "X", and then prevent the result if it matches "XX". If it doesn't match, a title XEMPTYX is created, and then stripped of the X's to make "EMPTY". Assuming that none of your indexes match "EMPTY", this should work. Change X to something else if it's too common for you. Likewise the word "EMPTY" if you want something even less likely to appear.  I just needed it to use clear text for my testing.

HTH
-- Mark

On Saturday, September 15, 2018 at 5:13:20 PM UTC-7, Magnus wrote:

Mark S.

unread,
Sep 17, 2018, 12:27:58 AM9/17/18
to tiddl...@googlegroups.com
Ok, this way may be more elegant, if you don't mind your text replaced by a message:


<$list filter="[{$:/state/table}minlength[1]]" emptyMessage="<br/><b>Search string too short</b><br/>">

<$reveal state="$:/state/table!!selection" type="match" text="auctor">
   
<br><br>

      <$set name="data" value="$:/_dictionary/auctor">

      <$list filter="[
<data>indexes[]search{$:/state/table}sort[title]]">
      ;{{!!title}}
      :<$transclude tiddler=<
<data>> index=<<currentTiddler>>/>
      </$list>
</$set>
</$reveal>
</$list>

It basically won't let results be shown unless the input field has 1 or more characters.

HTH
-- Mark

Magnus

unread,
Sep 17, 2018, 1:12:00 AM9/17/18
to TiddlyWiki
Thank you, that last one worked perfectly! :)
Reply all
Reply to author
Forward
0 new messages