Case insensitive fuzzy search of title in filter?

38 views
Skip to first unread message

MagoArcade

unread,
Aug 3, 2019, 10:06:33 AM8/3/19
to TiddlyWiki
Hi - I'm trying to write a fuzzy search routine. At the moment I only know how to search on the Prefix, but this only returns results on exact prefix matches of precise case. What I'm aiming for is something like below. 

Let's say I have 3 tiddlers:

"The cat sat on the mat"
"Cat littler needed"
"Fight like fish and dog"

If I type "cat" into the search box, it should return:
"The cat sat on the mat"
"Cat littler needed"

Present code (abridged + working code with debug}:

\define SearchTerm()
[prefix[{{$:/state/ItemSearch}}]]
\end


<!-- SET SUB ITEM -->


Set Parent Item:


<$edit-text tiddler="$:/_opTaskStore" field="itemsearch" tag="input" default="" class='tc-edit-texteditor' placeholder='Test text'/>


<$button set="$:/state/ItemSearch" setTo={{$:/_opTaskStore!!itemsearch}}>Search</$button>


test
: {{$:/state/ItemSearch}}


macrod
: <<SearchTerm>>


<$wikify name="SearchTermWikid" text=<<SearchTerm>> >


wikid
: <<SearchTermWikid>>


<$select field="SearchTermDD" class="tw-edit-texteditor myTextEdit">
<$list filter=<<SearchTermWikid>> >
<option value=<<currentTiddler!!title>>><$view field='title'/></option>
</$list>
</
$select>


</$wikify>


Mohammad

unread,
Aug 3, 2019, 10:48:01 AM8/3/19
to TiddlyWiki
Nice stuff!
 I also recommend to  have a look at 

-Mohammad

Ste Wilson

unread,
Aug 3, 2019, 10:59:36 AM8/3/19
to TiddlyWiki
I'm sure someone tackled this a while ago...

Mohammad

unread,
Aug 3, 2019, 11:04:34 AM8/3/19
to TiddlyWiki

MagoArcade

unread,
Aug 3, 2019, 12:08:12 PM8/3/19
to TiddlyWiki
Thanks all. I'd forgotten about regex, which solved it:

\define SearchTerm(term)
(?i)($term$)

\end


<!-- SET SUB ITEM -->


Set Parent Item:


<$edit-text tiddler="$:/_opTaskStore" field="itemsearch" tag="input" default="" class='tc-edit-texteditor' placeholder='Test text'/>


<$button set="$:/state/ItemSearch" setTo={{$:/_opTaskStore!!itemsearch}}>Search</$button>


test
: {{$:/state/ItemSearch}}


<$wikify name="SearchTermWikid" text=<<SearchTerm {{$:/state/ItemSearch}}>> >



wikid
: <<SearchTermWikid>>


<$select field="SearchTermDD" class="tw-edit-texteditor myTextEdit">
<$list filter="[regexp:<SearchTermWikid>]" emptyMessage="No Results" >

<option value=<<currentTiddler!!title>>><$view field='title'/></option>
</$list>
</
$select>


</$wikify>

The "(?i)" in the regex makes it case insensitive.
Reply all
Reply to author
Forward
0 new messages