Searching for fields which don't contain value

Hi,

this will search for ‘apple’ in the text of tiddlers with ‘pear’ contained in the field called ‘key’

<<list-links "[search:text[apple]] +[search:key[pear]]">>

How do I do the same search for tiddlers which don’t have ‘pear’ in the field?

Regards
Jon

According to the documentation for the search filter operator (see https://tiddlywiki.com/#search%20Operator) , you can precede it with an exclamation point (!) to find tiddlers that do not have the specified search term(s), like this:

<<list-links "[search:text[apple]] +[!search:key[pear]]">>

Note that this will find key fields that contain “pear” or “pearl” or even “appearance”, since all of those text values match the substring “pear”.

However, If your key field is list of space-separated items, you could use the contains filter operator (see https://tiddlywiki.com/#contains%20Operator) like this:

<<list-links "[search:text[apple]] +[!contains:key[pear]]">>

This will first parse the key field contents as a list and then look for items that are an exact match for the specified value, so that “pearl” and “appearance” won’t be considered as a match for “pear”.

Also, note that if the key field is expected to have just a single literal text value (i.e., NOT a list of values), then you can skip the search or contains filter operators and use the field filter operator (see https://tiddlywiki.com/#field%20Operator) instead, like this:

<<list-links "[search:text[apple]] +[!field:key[pear]]">>

and, because “…the syntax of a filter step treats any unrecognised filter operator as if it was the suffix to the field operator…”, you can simplify this further to just

<<list-links "[search:text[apple]] +[!key[pear]]">>

enjoy,
-e

Ah many thanks Eric - supremely helpful!

Regards
Jon

Hi Eric,

following on from

<<list-links "[search:text[apple]] +[!contains:key[pear]]">>

and making it positive for ease of explanation

<<list-links "[search:text[apple]] +[contains:key[pear]]">>

It seems that this will give a list where pear is the only value in the field, so it won’t give a result when the field contains other items as well.

Have I got this right ?

Regards
Jon

<<list-links "[search:text[apple]] +[has:feild[key]!contains:key[pear]]">>
This will search tiddler with apple in the text field and those only have key field but not pear in the key field.

So, it won’t return tiddler have not key field which can be many tiddlers.

Thanks Mohammad!

Regards
Jon