Sage
Welcome to Sage
Volume (8%) Hide Volume
Topics
Search Features
The Search Edit and Volume Search controls offer a rich set of search features.

Simple Search Strings

A simple search string consists of one or more words, separated by one or more whitespace characters. For example:

fluent sql

The above search string will find articles that contain both words fluent and sql, ignoring case. Articles are sorted by the number of occurrences of the search word(s). Sage excludes articles missing one or more of the search words.

Advanced Search Strings

Sage supports more sophisticated search strings, based on the following concepts…

  • The pipe operator, |, implements the familiar "or" operator.
  • The exclamation mark, !, implements the familiar "not" operator.
  • Quoted strings (using double-quotes: "...") escape characters that would otherwise have special meaning (such as pipes, parenthesis, etc).
  • Quoted strings have another purpose: finding words in a specific sequence.
  • Regular expressions are also supported.
  • Parenthesis characters, ( and ), group sub-expressions.
  • The colon operator, :, manipulates various flags, controlling options such as case sensitivity whole vs. partial word match, and more.
  • The semi-colon symbol, ;, is reserved for future expansion.

These concepts are discussed in detail in the following sections.

Conjunction: Adjacent Expressions

As indicated above, having two adjacent expressions (separated by whitespace) is an implicit "and" operator. For example…

abc !xyz 123

The above search string asks for articles containing both the strings abc and 123, but without the string xyz. Another example…

abc (x | y | z) def

The above search string ask for articles containing: the string abc, the string def, and at least one of the following: x, y, or z.

Disjunction: The Pipe Operator

The pipe symbol is the "or" operator. For example…

abc | xyz

The above search string asks for articles containing the words abc and/or xyz. Another example…

abc | xyz | (d e f)

The above search string asks for articles matching at least one of the following criteria:

  • Contain abc,
  • Contain xyz,
  • Contain d and e and f (in any order).

Negation: The Exclamation Operator

The exclamation mark is the "not" operator. For example…

abc !xyz

The above search expression asks for articles containing abc, excluding those that contain xyz. Another example…

fluent sql !(alder | ginkgo)

The above example asks for articles containing both fluent and sql, excluding those that contain alder and/or ginkgo.

Note

Sage does not permit exclamation as the top-level operator in a search expression. For example, all of these expressions are illegal…

!bug !(a b c) !(x | y | z)

More specifically, the top-level expression cannot be a negative expression. A negative expression is one of the following…

  • A chain of "or" expressions where any operand is a negative expression.
  • A chain of "and" expressions where every operand is a negative expression.
  • A "not" expression where the operand isn't a negative expression.

According to these rules, the following are also illegal…

x | !y | z !a !b !c x | (!a !b) | y

However, the following are allowed…

!a !b c x | (!a b) | y


Grouping with Parentheses

Use parentheses to group sub-expressions, for example…

(a b) | (x y)

The above expression asks for articles containing both a and b, and/or containing both x and y.

Note

Sage does not permit mixing "and" and "or" operators without explicit parenthesis. Most languages define "and" as having higher precedence than "or", and parentheses are not always required when mixing the two. However, Sage requires parentheses when mixing "and" and "or". For example…

a b | c

The above is not legal; use one of the following instead…

(a b) | c a (b | c)

The "not" operator has higher precedence that "and" or "or".


Short-Circuit Evaluation

The "and" Operator

The "and" operator performs the familiar short-circuit evaluation: if the left operand is false, the right operand is not evaluated.

The "not" Operator

The ! operator also performs a kind of short-circuit evaluation. For example, consider the search string fluent !(sql | vdb). If an article has one or more occurrences of fluent, it may count as a match, but not if it contains sql or vdb. Normally, the sub-expression (sql | vdb) would find any/all occurrences of sql and vdb, and count them all up. However, since this sub-expression is the operand of the ! operator, it is evaluated in such a way as to stop on the first occurrence of sql or vdb. In other words, the ! operator avoids counting up all the reasons why the article doesn't match, stopping at the first one.

This leads to an interesting, and potentially useful, side-effect. Consider these two search strings…

fluent (sql | vdb) fluent !!(sql | vdb)

They both return the same set of articles. However, the one with the double negative avoids counting the words sql and vdb. So, the order of the search results will differ. For the first one, results are ordered by the combined count of all three words. For the second one, results are ordered by the count of fluent only.

The "Or" Operator

Typically, the | operator evaluates both operands, even when the first one is true (to count all words involved). However, if the | operator is (directly or indirectly) a sub-expression of the ! operator, short-circuit kicks in: if the left operand is true, the right operand is not evaluated, because Sage knows that it isn't supposed to count everything (instead, it just needs to determine whether the count is zero or non-zero, in effect).

Quoted Strings

In a search string, you may use double-quote characters to build a quoted string. Such a string will escape special characters (pipe, parentheses, etc). To include a quote character in a string, simply double it up, as is the practice in SQL and Delphi. For example…

a | "x|y"

The above search string asks for articles containing the string a and/or containing the three-character string x|y.

In a quoted string, any sequence of one or more whitespace characters matches with one or more whitespace characters in the text being searched. For example…

"fluent sql"

The above search string matches articles containing the word fluent, followed by one or more whitespace characters, followed immediately by the word sql.

The characters (if any) before and after a quoted string must be whitespace or operators. For example, these are both illegal…

"abc"xyz xyz"abc"

A space is required in the above examples, as in…

"abc" xyz xyz "abc"

A space is not required if the character before/after the string is an operator…

("abc"|xyz)"123"!456

The above is allowed, and is equivalent to…

("abc" | xyz) "123" !456

Regular Expressions

Sage supports regular expressions, denoted by a quoted string with the r prefix…

registry | r"@Set.*Value"

The above matches articles containing the string registry, and/or containing the regular expression @Set.*Value (which looks for strings such as @SetPropBagValue and @SetRegValue).

This notation is an exception to the rule that the character before a quoted string must be an operator or whitespace.

Note

Regular expressions are not affected by the W or C flags – they have their own built-in mechanisms for controlling case sensitivity and whole word modes.


The R flag offers a slightly cleaner syntax, if the entire search string is a single regular expression.

Search Flags

Sage offers several flags to control various search-related options. Each flag is identified by a single letter…

Flag Description Top-Level
A All volumes Yes
T volume Titles Yes
V Volume links Yes
H Headings Yes
D Density Yes
R Regular expr Yes
W Whole words No
C Case-sensitive No

To use one or more flags, specify the flag name(s), followed by a colon, followed by an expression. For example…

cw:MiniCalc

The above search string looks for articles containing the whole word MiniCalc, case sensitively. This would not match the following strings: minicalc, MiniCalcExtras, or VDBMiniCalc.

Note

Flags apply to the entire remaining expression following the colon. For example…

c:a b c

The above looks for articles containing the strings a, b, and c – all case sensitive.


Applying Flags to Sub-Expressions

Except for flags appearing at the beginning of the search string, flags applying to a sub-expression must appear immediately after an open parenthesis – and they apply for the remainder of the parenthesized expression. For example…

a | (w:b c)

The above search string looks for articles containing the string a (partial word matching), and/or articles containing both b and c (whole words only). Thus, the above would match x b c but not xb c.

Top-Level Flags

As indicated in the table above, some flags are allowed at the top-level only. For example, the following is illegal…

a | (vw:b c)

The v flag, along with certain others, must be specified at the beginning of the search string. For example, the above should be written as follows…

v:a | (w:b c)

The A Flag: All Volumes

This flag, which may only appear at the top level, instructs Sage to search all volumes, including private and hidden volumes.

The T Flag: Volume Titles

This flag, which may only appear at the top level, instructs Sage to search only volume titles, and return links to volumes.

This flag cannot be used with the V and/or H flags.

The V Flag: Volume Links

This flag, which may only appear at the top level, instructs Sage to return links to volumes. Without this flag, Sage returns links to articles. With this flag, Sage searches all relevant articles, aggregates search results by volume, sorts the volumes, and returns a list of volume links.

The H Flag: Headings

This flag, which may only appear at the top level, instructs Sage to ignore the article contents, and search headings only (that is, titles of volumes, topics, articles, and sections).

The D Flag: Density Ranking

This flag, which may only appear at the top level, controls how Sage sorts search results. By default, search results are sorted by comparing the number of hits in the headings (titles), and as a tie-breaker, comparing the number of hits in the article content. With the D flag, Sage sorts search results by combining the headings and contents of each article, and comparing the density (the ratio of hits divided by text length). So, if two articles have the same number of occurrences of the search word, the shorter article will appear first (as it is more densely populated with the search word).

The R Flag: Regular Expressions

This flag, which may only appear at the top level, provides a more convenient way to search for a single regular expression. When this flag is present, all text after the colon is taken, verbatim, as the regular expression. For example, the following are equivalent…

r"ab*c""d" r:ab*c"d

As the above example illustrates, the R flag can be slightly less verbose. However, as this flag can only appear at the top level, you will still need to use the other syntax when a regular expression is only part of the overall search string. For example…

alpha beta r"ab*c""d

Note

Thus, it is illegal to combine the R flag with the W or C flags, as regular expressions have their own mechanisms to control the case sensitivity and whole word modes.


The W Flag: Whole Words

This flag instructs Sage to look for whole words only. To qualify as a whole word, the characters on either side of the word (if any) must not be: letters, digits, or underscores.

The C Flag: Case Sensitive

This flag instructs Sage to honor case (without this flag, Sage ignores case).

Disabling Flags

Sage provides a syntax for disabling a flag that has been enabled previously. When specifying the flag character(s), a dash indicates that the remaining character(s) will be disabled. For example…

w:xyz | (a b (c-w:c d) e f)

The above string asks for articles containing the string xyz (whole words, ignore case) and/or containing each of the following strings: a, b, c, d, e, and f (whole words only, ignore case, except for c and d, which honor case and allow partial word matching).

Note that the above could also be written as…

(w:xyz) | ((w:a b e f) (c:c d))

But as this example shows, it is sometimes much cleaner to use the dash.

Note

The only two flags that can be disabled are W and C.

Also, it is illegal for a flag to appear both before and after the dash, as in…

cw-w:a b c


Last Modified: 3/19 3:58:13 pm
In this article (top)  View article's Sage markup
3/19 3:58:13 pm