Empty filter with no results in some cases results in "1 matches"

In my wiki I use a list widget with a filter that parses a dynamic comma separated list of field names. A simple, equivalent filter would be as follows:

[[a, b, c]split[,]]

which is easy to test in Advanced Search.

The filter works as desired, except that it returns “1 matches” when the comma separated list is empty, while I expect it to return “0 matches”. This prevents me from using emptyMessage.

Strangely, when the comma is omitted:

[[]split[]]

the result is indeed “0 matches”.

Similarly, [[]] also returns “1 matches”.

It seems to me that filters with no input to work on should always return “0 matches”.

Is the above behavior by design? If so, what is the logic behind it?

It seems to me that the first thing to clarify here is the difference between “no value” (commonly called null, though in this case it’s closer to “empty list” or, as you could think of it, “no input”/“0 results”) and “empty string”. Perhaps one way to illustrate this would be by thinking about the following:

[[one,,three]split[,]]

This returns three results: one, an empty value, and three.

For even better illustration purposes, you could extend it a little bit:

[[one,,three]split[,]] :map[is[blank]then[(empty string)]else<currentTiddler>]

The above may be a little advanced, but it just replaces empty strings in the results with the value (empty string) so that you can see them in the results. (Try copying and pasting it into the advanced search.)

With that in mind, it is important to note:

  • Just as [[some value]] returns one result containing some value, [[]] returns one empty string result (not no results).
  • As such, [[]split[,]] is not acting on no inputs. It is acting on one input - an empty string. And it has no commas to split on, so it returns the (empty string) input unchanged (just like any other string with no commas will be returned unchanged).
  • As a special case, split[] returns one result for each character in the input. For example, [[test]split[]] returns t, e, s, and t. However, the input for an empty string (the input to [[]split[]] is an empty string, not no input) has no characters, and thus no results are returned.
3 Likes

Hi @Jan

If you try [[]!is[blank]split[]] you’ll see that the result is “0 matches”.

In filters, there’s a difference between an empty list and a list containing blank list items.
As such, your example of [[]] is not an empty list, it’s a list of 1 empty item.

I often get blank items with :map filter runs, where input items can be replaced by an empty value. It’s easy to get rid of these by inserting !is[blank] in your filters.

Fred

2 Likes

This solves the problem.
Thank you both also for the clarification.
J.