Precedence Evaluation


The ways that precedence rules and syntax affect the evaluation of queries are described below.

Precedence Rules

A Verity query expression is read using explicit precedence rules applying to the operators which are used. Although a query expression is read from left to right, some operators carry more weight than others; this affects the interpretation of the expression. For example, the AND operator takes precedence over the OR operator. For this reason, the following example is interpreted to mean: Look for documents that contain b and c, or documents that contain a.

a OR b AND c

To ensure that the OR operator is interpreted first, use parentheses as follows:

(a OR b) AND c

In general, the appropriate use of parentheses in query expressions, especially complex ones, ensures that the query expression is interpreted as intended.

Parentheses in Expressions

Parentheses indicate the order in which the directions are to be performed; information within parentheses is read first, then information outside parentheses is read next. There must be at least one space between operators and words used in the expression. The following example means: Look for documents that contain a and b, or documents that contain c.

(a AND b) OR c

When there are nested parentheses, start with the innermost level. The following example means: Look for documents that contain b or c as well as a, or that contain d.

(a AND (b OR c)) OR d

Prefix and Infix Notation

Words or topics that use any operator except evidence operators (SOUNDEX, STEM, THESAURUS, WILDCARD, and WORD) can be defined in prefix notation or in infix notation.

Prefix notation is a format that specifies that the operator is specified before the words or topics used with that operator. The following example means: Look for documents that contain a and b.

AND (a,b)

When prefix notation is used, precedence is explicit within the expression. The following example means: Look for documents that contain b and c first, then documents that contain a.

OR (a, AND (b,c))

Infix notation is a format that specifies that the operator is specified between each element within the expression. The following example means: Look for documents that contain a and b or documents that contain c.

a AND b OR c

When infix notation is used, precedence is implicit within the expression; for example, the AND operator takes precedence over the OR operator.





Copyright © 2001, Verity, Inc. All rights reserved.