(zettel (meta (back "00001007700000 00001007720000 00001007720500") (backward "00001007700000 00001007720000 00001007720500") (box-number "1") (created "20230707204706") (forward "00001006032500 00001007701000") (modified "20250626174255") (published "20250626174255") (role "manual") (syntax "zmk") (tags "#manual #search #zettelstore") (title "Query: Context Directive")) (rights 4) (encoding "") (content "A context directive calculates the __context__ of a list of zettel identifier.\nIt starts with the keyword ''CONTEXT''.\n\nOptionally you may specify some context details, after the keyword ''CONTEXT'', separated by space characters.\nThese are:\n* ''FULL'': additionally search for zettel with the same tags,\n* ''BACKWARD'': search for context only though backward links,\n* ''FORWARD'': search for context only through forward links,\n* ''DIRECTED'': search for context only in the same direction as the one that led to the current zettel.\n If the zettel is one of the initial zettel, search in both directions.\n* ''COST'': one or more space characters, and a positive integer: set the maximum __cost__ (default: 17),\n* ''MAX'': one or more space characters, and a positive integer: set the maximum number of context zettel (default: 200).\n* ''MIN'': one or more space characters, and a positive integer: set the minimum number of context zettel (default: 0).\n Takes precedence over ''COST'' and ''MAX''.\n\nIf neither ''BACKWARD'' nor ''FORWARD'' is specified, the search for context zettel will follow both backward and forward links.\n\nIf both ''BACKWARD'' and ''FORWARD'' are specified, the search for context zettel will be performed as ''DIRECTED''.\nInternally, ''DIRECTED'' is just a shorthand for specifying both ''BACKWARD'' and ''FORWARD''.\n\nIf any of the three direction specifiers ''BACKWARD'', ''FORWARD'', and ''DIRECTED'' is specified more than once, parsing of the thread directive is stopped.\nAll following text is then interpreted either as other directives or as a search term.\n\nThe cost of a context zettel is calculated iteratively:\n* Each of the specified zettel has a cost of 1.0.\n* Every zettel directly referenced by a specified zettel has a maximum cost of 4.0.\n* A zettel found as a single folge zettel or single precursor zettel inherits the cost of the originating zettel, plus 0.2.\n* A zettel found as a single sequel zettel or single prequel zettel inherits the cost of the originating zettel, plus 1.0.\n* A zettel discovered via another type of link, without being part of a [[set of zettel identifiers|00001006032500]], inherits the cost of the originating zettel, plus 2.0.\n* 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.\n* 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.\n If a zettel shares more than one tag with the originating zettel, a 90% discount is applied per additional tag.\n This rules applies only if the ''FULL'' directive has been specified.\n\nThe maximum cost is only checked for all zettel that are not directly reachable from the initial, specified list of zettel.\nThis ensures that initial zettel that have only a highly used tag, will also produce some context zettel.\n\nDespite 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.\nIt 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.\n\nThis directive may be specified only once as a query directive.\nA second occurence of ''CONTEXT'' is interpreted as a [[search expression|00001007701000]].\nIn 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."))