1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-06 12:13:16 +00:00
TiddlyWiki5/tw5.com/tiddlers/concepts/TiddlerFilters.tid

65 lines
4.0 KiB
Plaintext
Raw Normal View History

2012-05-20 17:47:11 +00:00
title: TiddlerFilters
tags: docs concepts
2012-05-20 17:47:11 +00:00
TiddlyWiki has a special syntax for expressing filters. They can be used to select tiddlers for an operation, or to filter a set of tiddlers to add or remove members.
The mechanism is easiest to understand by first presenting some example filter strings:
2012-06-22 14:45:32 +00:00
* `HelloThere` - the single tiddler titled `HelloThere` (if it exists)
* `[[A Title With Several Words]]` - the single tiddler titled `A Title With Several Words` (if it exists)
* `[title[MyTiddler]]` - the single tiddler titled `MyTiddler` (if it exists)
* `HelloThere Introduction` - The tiddlers titled `HelloThere` and `Introduction` (if they exist)
* `[tag[important]]` - any tiddlers with the tag `important`
* `[!tag[important]]` - any tiddlers not with the tag `important`
* `[tag[important]sort[title]]` - any tiddlers with the tag `important` sorted by title
* `[tag[important]!sort[title]]` - any tiddlers with the tag `important` reverse sorted by title
* `[[one][two][three]tag[tom]]` - any of the tiddlers called `one`, `two` or `three` that exist and are tagged with tom`
* `[[one][two][three]] [tag[tom]]` - any of the tiddlers called `one`, `two` or `three` that exist, along with all of the source tiddlers that are tagged with `tom`
* `[tag[tom]] [tag[harry]] -[[one][two][three]]` - all tiddlers tagged either `tom` or `harry`, but excluding `one`, two` and `three`
* `[[MyTiddler]tags[]]` - all tiddlers being used as tags on the tiddler `MyTiddler`
* `[[MyTiddler]tagging[]]` - all tiddlers being tagged with `MyTiddler`
! Explanation
2012-05-20 17:47:11 +00:00
A filter string consists of one or more filter operations, each comprising one or more filter operators with associated operands.
The operators look like `[operator[operand]]`, where `operator` is one of:
2012-05-20 17:47:11 +00:00
* ''title'': selects the tiddler with the title given in the operand
* ''is'': tests whether a tiddler is a member of the system defined set named in the operand (see below)
* ''has'': tests whether a tiddler has a specified field
* ''sort'': sorts the tiddlers by a given field
2012-06-22 14:45:32 +00:00
* ''sort-case-sensitive'': sorts the tiddlers by a given field with case sensitivity (ie, "a" and "A" are sorted differently)
* ''prefix'': tests whether a tiddlers title starts with a particular prefix
2012-05-20 17:47:11 +00:00
* ''limit'': limits the number of subresults
* ''tag'': tests whether a given tag is (`[tag[mytag]]`) or is not (`[!tag[mytag]]`) present on the tiddler
2012-06-04 20:28:30 +00:00
* ''{field}'': tests whether a tiddler field has a specified value (`[modifier[Jeremy]]`) or not (`[!modifier[Jeremy]]`)
2012-06-22 14:45:32 +00:00
* ''tags'': selects the tags on the currently selected tiddlers
* ''tagging'': selects the tiddlers tagged with the currently selected tiddlers
2012-05-20 17:47:11 +00:00
An operator can be negated with by preceding it with `!`, for example `[!tag[Tommy]]` selects the tiddlers that are not tagged with `Tommy`.
The operator defaults to `title` if omitted, so `[[HelloThere]]` is equivalent to `[title[HelloThere]]`. If there are no spaces in the title, then the double square brackets can also be omitted: `HelloThere`.
The operands available with the `is` operator are:
2012-06-19 07:56:45 +00:00
* ''shadow'': selects all shadow tiddlers
* ''current'': selects the current ContextTiddler
2012-05-20 17:47:11 +00:00
Operators are combined into logically ANDed expressions by bashing them together and merging the square brackets:
2012-05-20 17:47:11 +00:00
{{{
[tag[one]] [tag[two]] ---> [tag[one]tag[two]]
}}}
Operations can be preceded with `-` to negate their action, removing the selected tiddlers from the results. For example, `[tag[Tommy]] -HelloThere -[[Another One]]` selects all tiddlers tagged with `Tommy` except those titled `HelloThere` or `Another One`.
Operations can be preceded with `+` in order to make them apply to all of the current results, rather than the original source. For example, `[tag[Jeremy]] [tag[Tommy]] +[sort[title]]` selects the tiddlers tagged `Tommy` or `Jeremy`, and sorts them by the `title` field.
Filters are processed with the following elements:
2012-05-20 17:47:11 +00:00
* a string of filter operations, each made up of one or more filter operators
* the incoming source tiddlers
* the overall result stack
* the subresult stack of the tiddlers selected by the current operation