This is a stripped-down version of a single section of Grok TiddlyWiki, optimized for fast loading and readability by search engines. Some features are missing.

For the full Grok TiddlyWiki experience, please visit the wiki version of this page.

Common Filter Operators

9th April 2021 at 11:50am

There are a lot of different operators available for use in filters, and many of them are very specific and rarely needed, but hard to do without in those rare circumstances. Thus, it is not worth trying to learn them all. Instead, anytime you can't remember the details of or don't know of an appropriate operator, you should review the comprehensive documentation. You might want to bookmark that page right now.

The list can be overwhelming at first, so let's take a look at the most common operators.

Links

  • backlinks[]: Get all of the tiddlers that link to the input tiddler.
    • Example: [[JaneDoe]backlinks[]] gets all tiddlers that link to Jane.
  • links[]: Get all of the tiddlers that the input tiddler links to.
    • Example: [tag[Meeting]links[]] finds all tiddlers that were mentioned in any meeting.

Tags

  • tag[X]: Keep all of the input tiddlers that have the tag X.
    • Example: [tag[Application]] finds all tiddlers tagged Application.
  • tagging[]: Get all tiddlers in the wiki that are tagged with the input tiddler.
    • Example: [[Application]tagging[]] is the same thing as [tag[Application]].
    • You need to use tagging[] instead of tag[] when you don't know what tag(s) you want to look for ahead of time. For instance, let's say we wanted to find all tiddlers that are part of any project. In our wiki, we decided to tag our projects Project, then tag the tiddlers that are part of that project with the project tiddler (e.g., the parts of the OnboardingProject are tagged OnboardingProject). So we could use the filter [tag[Project]tagging[]] – the first filter step returns all project tiddlers, and the second step finds all the tiddlers that any of those tiddlers is tagging.

Fields

  • field:fieldname[value]: Keep all of the input tiddlers that have a field called fieldname with a value of value.
    • Example: [field:phone[888-555-1234]] returns JaneDoe because that's Jane's phone number.
    • This usage is common enough that you can shorten it to fieldname[value], provided that your field name doesn't conflict with another filter operator (for instance, if you had a field called backlinks, you would have to use field:backlinks to refer to that field, since there is a backlinks filter operator already).
  • contains:fieldname[value]: Like field:, but treats the field as a list containing multiple values, and only requires value to be one of the items in the list.
    • Example: [contains:family[JohnDoe]] returns JaneDoe and EmilyDoe because both of them have John as a family member.
  • has[fieldname]: Keep all of the input tiddlers that have a non-empty field called fieldname.
    • Example: [tag[Contact]!has[phone]] finds any contact tiddlers we forgot to add phone numbers to.
    • For filtering purposes, TiddlyWiki treats empty fields and nonexistent fields the same.
  • search:field1,field2[mysearch]: Keep all of the input tiddlers whose field1 or field2 field matches the search query mysearch.
    • Any number of fields can be listed in the suffix, separated by commas. The single suffix * searches all fields. If no suffix is provided, the tags, title, and text fields are searched.
    • Multiple words in the search query are searched separately with all words required to be somewhere in the text, and case is ignored, so that my search will find the phrase “Search my wiki”, but not “Search here”. You can change this behavior by adding an additional suffix; see the documentation for details.

Miscellaneous

  • count[]: Output a single value describing how many input tiddlers were passed to the operator.
    • Example: [tag[Meeting]count[]] returns 3 if we have 3 tiddlers tagged Meeting.
  • sort[field]: Sort the input tiddlers by field.
    • Example: [tag[Meeting]sort[at]] shows all meetings from earliest to latest.
    • The sort is not case-sensitive; uppercase and lowercase letters sort identically.
    • Adding a ! in front of sort reverses the order, showing all meetings from latest to earliest.
    • Leaving out the field, writing just sort[], sorts by the title.
  • get[field]: Take all of the input tiddlers and output the values of the field field on those tiddlers.
    • Example: [[JaneDoe]get[email]] yields Jane's email address.

Exercises

Exercise: (m) [Ex:CreatingMoreFilters]

Compose and run filters to answer the following questions:

  1. How many tiddlers are in the wiki?
  2. How many of those are system tiddlers?
  3. What meetings contain a link to JaneDoe?
    • Hint: Work backwards.
  4. Which contact has the alphabetically earliest phone number?
  5. Which tiddlers have text in a field called at?
  6. Which tiddlers contain the words JaneDoe and help somewhere in their text field? Use only a single filter step.
go to answer

Exercise: (m) [Ex:JohnDoeInAnyField]

In an exercise in the Searching section, we noted that a search for JohnDoe did not find places where John was mentioned somewhere other than the text field. Write and test a filter that finds mentions of John in any field.

go to answer

Exercise: (M) [Ex:AlphabeticallyLastDescription]

What is the alphabetically last description that any button on the editor toolbar uses? (The description is what shows up when you hover over the button, minus the indication of the keyboard shortcut. No cheating by hovering over every button!)

You'll need some additional information for this one:

  • Remember that everything's a tiddler? Buttons in TiddlyWiki's interface are tiddlers too!
  • A tiddler is part of the editor toolbar if it is tagged $:/tags/EditorToolbar.
  • You'll need to start your filter with all[shadows] to get any results.
  • Your filter expression will have more steps than any we've seen so far. Add one step to the filter expression at a time, inspecting the result to determine how you need to modify the list (what step you need to add) next. You'll eventually reach a point where you have a bunch of results that are wrapped in curly braces, like {{$:/language/Buttons/Paint/Description}}. When you get here, add the following filter steps to the end of your filter: split[{{]split[}}].

And here are two hints if you need them:

  1. How do you think we would define the description of a button in the TiddlyWiki data model?
  2. The content of a language tiddler, like $:/language/Buttons/Paint/Description, is stored in its text field.

This one is intended to be a little bit above your level at the moment – we won't get to some of the concepts involved until chapter 6, Looking Under the Hood – so you might not be able to figure it out. But spend some time working on it before you look at the answer.

go to answer

Takeaways

Takeaways are not available in the static version of Grok TiddlyWiki. Visit the wiki version of this page to study takeaways.

↑ 3: Filtering and Formatting