((p "A search term allows you to specify one search restriction." " " "The result " (a (@ (href . "00001007700000")) "search expression") ", which contains more than one search term, will be the applications of all restrictions.") (p "A search term can be one of the following (the first three term are collectively called " (em "search literals") "):") (ul (li (p "A metadata-based search, by specifying the name of a " (a (@ (href . "00001006010000")) "metadata key") ", followed by a " (a (@ (href . "00001007705000")) "search operator") ", followed by an optional " (a (@ (href . "00001007706000")) "search value") ".") (p "All zettel containing the given metadata key with a allowed value (depending on the search operator) are selected.") (p "If no search value is given, then all zettel containing the given metadata key are selected (or ignored, for a negated search operator).")) (li (p "An optional " (a (@ (href . "00001007705000")) "search operator") ", followed by a " (a (@ (href . "00001007706000")) "search value") ".") (p "This specifies a full-text search for the given search value.") (p "However, the operators " (@L (@H "“") "less" (@H "”")) " and " (@L (@H "“") "greater" (@H "”")) " are not supported, they are internally translated into the " (@L (@H "“") "match" (@H "”")) " operators." " " "Similar, " (@L (@H "“") "not less" (@H "”")) " and " (@L (@H "“") "not greater" (@H "”")) " are translated into " (@L (@H "“") "not match" (@H "”")) "." " " "It simply does not make sense to search the content of all zettel for words less than a specific word, for example.") (p (strong "Note:") " the search value will be normalized according to Unicode NKFD, ignoring everything except letters and numbers." " " "Therefore, the following search expression are essentially the same: " (kbd "\"search syntax\"") " and " (kbd "search syntax") "." " " "The first is a search expression with one search value, which is normalized to two strings to be searched for." " " "The second is a search expression containing two search values, giving two string to be searched for.")) (li (p "A metadata key followed by " (@L (@H "“") (kbd "?") (@H "”")) " or " (@L (@H "“") (kbd "!?") (@H "”")) ".") (p "Is true, if zettel metadata contains / does not contain the given key.")) (li (p "The string " (kbd "OR") " signals that following search literals may occur alternatively in the result.") (p "Since search literals may be negated, it is possible to form any boolean search expression." " " "Any search expression will be in a " (a (@ (href . "https://en.wikipedia.org/wiki/Disjunctive_normal_form") (rel . "external")) "disjunctive normal form") ".") (p "It has no effect on the following search terms initiated with a special uppercase word.")) (li (p "The string " (kbd "PICK") ", followed by a non-empty sequence of spaces and a number greater zero (called " (@L (@H "“") "N" (@H "”")) ").") (p "This will pick randomly N elements of the result list, preserving the order of that list." " " "A zero value of N will produce the same result as if nothing was specified." " " "If specified multiple times, the lower value takes precedence.") (p "Example: " (kbd "PICK 5 PICK 3") " will be interpreted as " (kbd "PICK 3") ".")) (li (p "The string " (kbd "ORDER") ", followed by a non-empty sequence of spaces and the name of a metadata key, will specify an ordering of the result list." " " "If you include the string " (kbd "REVERSE") " after " (kbd "ORDER") " but before the metadata key, the ordering will be reversed.") (p "Example: " (kbd "ORDER published") " will order the resulting list based on the publishing data, while " (kbd "ORDER REVERSE published") " will return a reversed result order.") (p "An explicit order field will take precedence over the random order described below.") (p "If no random order is effective, a " (code "ORDER REVERSE id") " will be added." " " "This makes the sort stable.") (p "Example: " (code "ORDER created") " will be interpreted as " (code "ORDER created ORDER REVERSE id") ".") (p "Any ordering by zettel identifier will make following order terms to be ignored.") (p "Example: " (code "ORDER id ORDER created") " will be interpreted as " (code "ORDER id") ".")) (li (p "The string " (kbd "RANDOM") " will provide a random order of the resulting list.") (p "Currently, only the first term specifying the order of the resulting list will be used." " " "Other ordering terms will be ignored.") (p "A random order specification will be ignored, if there is an explicit ordering given.") (p "Example: " (kbd "RANDOM ORDER published") " will be interpreted as " (kbd "ORDER published") ".")) (li (p "The string " (kbd "OFFSET") ", followed by a non-empty sequence of spaces and a number greater zero (called " (@L (@H "“") "N" (@H "”")) ").") (p "This will ignore the first N elements of the result list, based on the specified sort order." " " "A zero value of N will produce the same result as if nothing was specified." " " "If specified multiple times, the higher value takes precedence.") (p "Example: " (kbd "OFFSET 4 OFFSET 8") " will be interpreted as " (kbd "OFFSET 8") ".")) (li (p "The string " (kbd "LIMIT") ", followed by a non-empty sequence of spaces and a number greater zero (called " (@L (@H "“") "N" (@H "”")) ").") (p "This will limit the result list to the first N elements, based on the specified sort order." " " "A zero value of N will produce the same result as if nothing was specified." " " "If specified multiple times, the lower value takes precedence.") (p "Example: " (kbd "LIMIT 4 LIMIT 8") " will be interpreted as " (kbd "LIMIT 4") "."))) (p "You may have noted that the specifications of first two items overlap somehow." " " "This is resolved by the following rule:") (ul (li "A search term containing no " (a (@ (href . "00001007705000")) "search operator character") " is treated as a full-text search.") (li "The first search operator character found in a search term divides the term into two pieces." " " "If the first piece, from the beginning of the search term to the search operator character, is syntactically a metadata key, the search term is treated as a metadata-based search.") (li "Otherwise, the search term is treated as a full-text search.")) (p "If a term like " (kbd "PICK") ", " (kbd "ORDER") ", " (kbd "ORDER REVERSE") ", " (kbd "OFFSET") ", or " (kbd "LIMIT") " is not followed by an appropriate value, it is interpreted as a search value for a full-text search." " " "For example, " (kbd "ORDER 123") " will search for a zettel containing the strings " (@L (@H "“") "ORDER" (@H "”")) " (case-insensitive) and " (@L (@H "“") "123" (@H "”")) "."))