Filter/Search problem

89 views
Skip to first unread message

Stephen Kimmel

unread,
Dec 12, 2019, 2:01:16 PM12/12/19
to TiddlyWiki
I want to combine a pair of search operators within a single filter where one will be positive and the other negative. For example, I might want a list of all the tiddlers that contain the word "Mark" but exclude all the tiddlers that contain the word "temple." The solution I suspect would involve an expression that looks something like

[search[Mark]!search[Temple]]

but, of course, I want to use variables in the expression. So what I have at the moment has an expression that looks like this:

search{$:/temp/possearch}!search{$:/temp/negsearch}

The problem I'm having occurs when $:/temp/negsearch is either empty or doesn't exist. In that set of circumstances, I get no matches. I would like the search to act as though it were

search{$:/temp/possearch}

or

search{$:/temp/possearch}!search[xyz123]

but I can't figure out how to do that.

Any ideas?

Eric Shulman

unread,
Dec 12, 2019, 2:29:14 PM12/12/19
to TiddlyWiki
If I understand your goal correctly, you want to get one list that matches a certain filter... and then remove some of the items that match another filter.

To do that, use separate filter "runs", where the second filter has a leading "-" (minus), like this:

<$list filter="[search{$:/temp/possearch}] -[search{$:/temp/negsearch}]">
   ... stuff here ...
</$list>

enjoy,
-e

Stephen Kimmel

unread,
Dec 12, 2019, 9:06:29 PM12/12/19
to TiddlyWiki
Unfortunately, if $:/temp/negsearch doesn't exist or the text field is blank, then this gives me nothing at all.  That's the problem I'm trying to avoid. I've tried with a "missing" operator and an "else" operator and that doesn't seem to work either.

TonyM

unread,
Dec 12, 2019, 10:02:28 PM12/12/19
to TiddlyWiki
Stephan

{tiddlername} in filters or {{tiddlername}} in wiki text are not variables, they are transclusions. We use <variablename> in filters and <<variablename>> in wiki text

If you choose to use transclusions the thing you are transcluding needs to contain the value you want used.

Given Erics guidance the simple form is
[search[Mark]] -[search[Temple]]

Search defaults to tagstext and title if field list:  is blank

So If I read your example $:/temp/possearch should contain "Mark" and $:/temp/negsearch should contain "Temple".

Then the filter
[search{$:/temp/possearch}] -[search{$:/temp/negsearch}]
should work.,

You could use the edit-text widget to let users enter the value, or even a select widget if you already can search for and identify possible values.

Another way to do this is use variables created from transclusions
\define posssearch() {{$:/temp/possearch}}
\define negsearch() {{$:/temp/negsearch}}}

then use the filter
[search<possearch>] -[search<negsearch>]

Regards
Tony

Stephen Kimmel

unread,
Dec 12, 2019, 10:51:28 PM12/12/19
to TiddlyWiki
Apparently clarity is not my strong suit.

Yes. Both your and Eric's solutions work fine when $:/temp/possearch contains "Mark" and $:/temp/negsearch contains "Temple." I get a list of tiddlers.

Now go to the next step. What happens with your solution when $:/temp/possearch contains "Matthew" and $:/temp/negsearch is empty? Using [search<possearch>] -[search<negsearch>] I get nothing at all. How do I fix that?

Mark S.

unread,
Dec 12, 2019, 11:08:14 PM12/12/19
to TiddlyWiki
Here's my version:

<$list filter="[search{possearch}!search{negsearch}] ~[search{possearch}] -[[possearch]] -$:/HistoryList">
   <
<currentTiddler>><br/>
</$list>

I changed $:/temp/possearch and $:/temp/negsearch for my research. I'm sure you'll see how to change them back. Because the possearch term will always contain the thing to be searched, it needed to be subtracted. Same for the HistoryList.

This worked in my test, including when negsearch was not present.

HTH

Mark S.

unread,
Dec 12, 2019, 11:11:32 PM12/12/19
to TiddlyWiki
The reason this doesn't work is because when $:/temp/negsearch is missing, then search{$:/temp/negsearch} will return EVERY tiddler that contains nothing -- i.e., every single tiddler.

Mohammad

unread,
Dec 13, 2019, 12:17:31 AM12/13/19
to TiddlyWiki
The reason is you have both part empty so both part returns the whole list of tiddlers and negative sign cause all-all = nothing

1. create those temp tiddler
2. put something in them
3. run the code
4. now empty the negsearch tiddler
5. run again
6. it works

Your mistake is here you think if you put Mark and Mathew like
Mark Mathew

Then your search will find tiddlers has Mark OR Mathew, but your code search for composition "Mark Mathew"
 Furthermore if you use [search[]] TW returns all tiddlers! When you have empty negsearch you return all tiddlers.



Use list field or first convert your text to a list of tiddlers.

Stephen Kimmel

unread,
Dec 13, 2019, 8:51:10 PM12/13/19
to TiddlyWiki
The tilde (~) operator was what I was missing. Thanks.
Reply all
Reply to author
Forward
0 new messages