A context directive calculates the context of a list of zettel identifier. It starts with the keyword CONTEXT.
Optionally you may specify some context details, after the keyword CONTEXT, separated by space characters. These are:
- BACKWARD: search for context only though backward links,
- FORWARD: search for context only through forward links,
- COST, one or more space characters, and a positive integer: set the maximum cost (default: 17),
- MAX, one or more space characters, and a positive integer: set the maximum number of context zettel (default: 200).
If no BACKWARD and FORWARD is specified, a search for context zettel will be done though backward and forward links.
The cost of a context zettel is calculated iteratively:
- Each of the specified zettel hast a cost of one.
- A zettel found as a single folge zettel or single precursor zettel has the cost of the originating zettel, plus one.
- A zettel found as a single successor zettel or single predecessor zettel has the cost of the originating zettel, plus two.
- A zettel found via another link without being part of a set of zettel identifier, has the cost of the originating zettel, plus three.
- A zettel which is part of a set of zettel identifier, has the cost of the originating zettel, plus one of the three choices above and multiplied with roughly a logarithmic value based on the size of the set.
- A zettel with the same tag, has the cost of the originating zettel, plus the number of zettel with the same tag (if it is less than eight), or the cost of the originating zettel plus two, multiplied by number of zettel with the same tag divided by four.
The maximum cost is only checked for all zettel that are not directly reachable from the initial, specified list of zettel. This ensures that initial zettel that have only a highly used tag, will also produce some context zettel.
Despite its possibly complicated structure, this algorithm ensures in practice that the zettel context is a list of zettel, where the first elements are “near” to the specified zettel and the last elements are more “distant” to the specified zettel. It also penalties zettel that acts as a “hub” to other zettel, to make it more likely that only relevant zettel appear on the context list.
This directive may be specified only once as a query directive. A second occurence of CONTEXT is interpreted as a search expression. In most cases it is easier to adjust the maximum cost than to perform another context search, which is relatively expensive in terms of retrieving power.