(((meta (@ (content . "Query: Context Directive") (name . "title"))) (meta (@ (content . "manual") (name . "role"))) (meta (@ (content . "#manual #search #zettelstore") (name . "tags"))) (meta (@ (content . "zmk") (name . "syntax"))) (meta (@ (content . "00001007700000 00001007720000 00001007720500") (name . "back"))) (meta (@ (content . "00001007700000 00001007720000 00001007720500") (name . "backward"))) (meta (@ (content . "1") (name . "box-number"))) (meta (@ (content . "(c) 2020-present by Detlef Stern ") (name . "copyright"))) (meta (@ (content . "20230707204706") (name . "created"))) (meta (@ (content . "00001006032500 00001007701000") (name . "forward"))) (meta (@ (content . "en") (name . "lang"))) (meta (@ (content . "EUPL-1.2-or-later") (name . "license"))) (meta (@ (content . "20250626174255") (name . "modified"))) (meta (@ (content . "20250626174255") (name . "published"))) (meta (@ (content . "public") (name . "visibility")))) (p "A context directive calculates the " (em "context") " of a list of zettel identifier." " " "It starts with the keyword " (kbd "CONTEXT") ".") (p "Optionally you may specify some context details, after the keyword " (kbd "CONTEXT") ", separated by space characters." " " "These are:") (ul (li (kbd "FULL") ": additionally search for zettel with the same tags,") (li (kbd "BACKWARD") ": search for context only though backward links,") (li (kbd "FORWARD") ": search for context only through forward links,") (li (kbd "DIRECTED") ": search for context only in the same direction as the one that led to the current zettel." " " "If the zettel is one of the initial zettel, search in both directions.") (li (kbd "COST") ": one or more space characters, and a positive integer: set the maximum " (em "cost") " (default: 17),") (li (kbd "MAX") ": one or more space characters, and a positive integer: set the maximum number of context zettel (default: 200).") (li (kbd "MIN") ": one or more space characters, and a positive integer: set the minimum number of context zettel (default: 0)." " " "Takes precedence over " (kbd "COST") " and " (kbd "MAX") ".")) (p "If neither " (kbd "BACKWARD") " nor " (kbd "FORWARD") " is specified, the search for context zettel will follow both backward and forward links.") (p "If both " (kbd "BACKWARD") " and " (kbd "FORWARD") " are specified, the search for context zettel will be performed as " (kbd "DIRECTED") "." " " "Internally, " (kbd "DIRECTED") " is just a shorthand for specifying both " (kbd "BACKWARD") " and " (kbd "FORWARD") ".") (p "If any of the three direction specifiers " (kbd "BACKWARD") ", " (kbd "FORWARD") ", and " (kbd "DIRECTED") " is specified more than once, parsing of the thread directive is stopped." " " "All following text is then interpreted either as other directives or as a search term.") (p "The cost of a context zettel is calculated iteratively:") (ul (li "Each of the specified zettel has a cost of 1.0.") (li "Every zettel directly referenced by a specified zettel has a maximum cost of 4.0.") (li "A zettel found as a single folge zettel or single precursor zettel inherits the cost of the originating zettel, plus 0.2.") (li "A zettel found as a single sequel zettel or single prequel zettel inherits the cost of the originating zettel, plus 1.0.") (li "A zettel discovered via another type of link, without being part of a " (a (@ (href . "00001006032500")) "set of zettel identifiers") ", inherits the cost of the originating zettel, plus 2.0.") (li "A zettel that is part of a set of zettel identifiers, inherits the cost of the originating zettel, plus one of the four costs above, multiplied by a value that grows roughly in a linear-logarithmic fashion based on the size of the set.") (li "A zettel sharing the same tag inherits the cost of the originating zettel, plus a linear-logarithmic value based on the number of zettel sharing that tag." " " "If a zettel shares more than one tag with the originating zettel, a 90% discount is applied per additional tag." " " "This rules applies only if the " (kbd "FULL") " directive has been specified.")) (p "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.") (p "Despite its possibly complicated structure, this algorithm ensures in practice that the zettel context is a list of zettel, where the first elements are " (@L (@H "“") "near" (@H "”")) " to the specified zettel and the last elements are more " (@L (@H "“") "distant" (@H "”")) " to the specified zettel." " " "It also penalties zettel that acts as a " (@L (@H "“") "hub" (@H "”")) " to other zettel, to make it more likely that only relevant zettel appear on the context list.") (p "This directive may be specified only once as a query directive." " " "A second occurence of " (kbd "CONTEXT") " is interpreted as a " (a (@ (href . "00001007701000")) "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 effort."))