Filtering on fields and values containing spaces

Suppose I have a tiddler with a field called “My field” containing a value of “some value” - the key point here being that both the field name and the value contain spaces.

If I alter terms to “myField” and “some_value” (i.e. remove the spaces), I can construct a filter to find this tiddler such as:

[contains:myField[some_value]]

How should I modify this filter to work with the original field name and value complete with spaces? My attempts so far have yielded nothing but non-functional bracket soup…

Have you tried [contains:my Field[some value]]?

The only part I am unsure about is the “my Field” used as a suffix.

Perhaps you need to step back and look at other field operators.

The [contains:my Field[some value]] syntax does not seem to work for me - it returns zero results. I have just discovered that if I switch the contains operator for the field operator, it works perfectly.

In fact, it even works without any operator at all! As in just [my Field[some value]].

I’m still not sure why the contains operator seems to have a different handling of the spaces, but for now it seems to have been a bit of a red herring in reaching my goal in any case.

In the contains you are providing the field name in a suffix in the other form its an operator name.

That works because you are simply matching the value in a field. The contains is used if you are checking if a value is inside of a list field, and in your example, the “my field” is not a list field in the way you are using it. Technically it is a list field with 2 items, “some” and “value”, but the way you are wanting to reference it as a whole text value of “some value”. What you are describing is simply a field that has some text in it that you want to match exactly, which is not what the contains operator is for.

[my field[some value]] is as basic a filter run as you can get and is the proper way to check if the the text inside that field is exactly what you put in the filter, but if it contains more than just that text, you would need to use the search operator, such as this:

[search:my field:literal[some value]]

This would find that exact value, even if there was other text surrounding that value.

Again, it seems like you only have that exact value in that field and you simply want to display any tiddlers where the “my field” has the exact text of “some value”, which is just your most basic filter run.

3 Likes

Thanks for the explanations @TW_Tones and @CasperBooWisdom. I think I pretty much get it now. It looks like my problem started where I accidentally used contains for a similar operation earlier on, and because neither my field nor the value in it in the case contained a space, it worked OK (even though it’s not strictly the correct operator for such a basic filter operation).

So for the current case, I never even thought whether it was the right operator, but just copied my early use and then put all my efforts into enclosing the “parameters” in a variety of brackets (of course to no avail).

Another easy lesson learned the hard way!

And just for reference, the reason that you do not need to include the field: operator is because by default, if tiddlywiki does not recognize a filter operator, it automatically assumes that the unrecognized operator is a suffix of the field: operator.

So [my field[some value]] is just a shorthand for [field:my field[some value]], but only as long as “my field” is not the name of another filter operator. So this would not work if you have a field called sort, for instance, in which case you would have to include the field: operator which would be [field:sort[some value]]

Having field names with space will cause you a lot of similar problems in the future. So I suggest to avoid spaces in field names.

Just an advice, which may make your live easier.

I support @pmario suggestion to avoid spaces in fieldnames and I commonly use hyphens instead eg; field-list where -list implies it has multiple values, and I use list ops actions to manipulate it.

  • One reason to avoid spaces is if and when you do use spaces in fields names it is for a specific purpose, for example to have a fieldname equal to a tiddler name.
    • This is most likely rare and needs to be implemented only if you have a detailed knowledge of the way we use delimiters.
  • Even then I would be tempted to replace spaces with _ underscores and when needed reverse it.
  • Also keep in mind the value of the relink plugin and if whatever you do, can you make use of this when you need it. eg when referencing a fieldname.

@pmario @TW_Tones yes, I think you’re right about avoiding spaces. I more or less came to that opinion myself on reflecting on this little issue. TW has plenty enough complexity of its own, without me adding extra difficulties!