Home  Back to Search (800) 955 - 5884 


Boolean operators

You can use the Boolean operators AND, OR, and NOT in both content and property queries. The Boolean operator NEAR can be used only in content queries. You can use Boolean operators in both long-form and short-form queries. For more information on long-form and short-form queries, see Query language forms.

When you use the NEAR operator in a query, a document matches the query if the words are within 50 words of each other in the document. The closer together the words are, the higher the rank that is assigned to the document in the result set. If the words are more than 50 words apart, they are not considered near enough, and the document is assigned a rank of zero. The NEAR operator can be applied only to words or phrases.

In content queries, use the NOT operator only after the AND operator. Use the NOT operator only to exclude documents that match a previous content restriction. For property-value queries, the NOT operator can be used apart from the AND operator.

The following table explains the Boolean operators and their associated symbols.

Operator Long form Short form
AND AND &
OR OR |
NOT AND NOT &!
NEAR NEAR Near, ~

Boolean operators are available only in English.

The following table shows some examples of the use of Boolean operators:

To search for Long form Short form Result
Two terms in the same document red and dog red & dog Documents with both the words "red" and "dog"
Either of two terms in a document red or dog red | dog Documents with the words "red" or "dog"
One term without a second term red and not dog red & ! dog Documents with the word "red" but not "dog"
Documents not matching a property value not {prop name=size} = 100 ! @size = 100 Documents that are not 100 bytes
Two terms that are close together in the same document red near dog red ~ dog Documents with the word "red" near the word "dog"
Either of two terms and not two other terms if they are close together red or dog and not (black near cat) red | dog &! (black~cat) Documents with the word "red" or "dog" and not the words "black" and "cat" if they are within 50 words of each other

Note

  • Use quotation marks around the query phrase if it contains a word that is a Boolean operator. For example, "horse and rider" will be evaluated as a phrase, not as a Boolean expression.

Order of precedence rules

Boolean operators are evaluated in the following order:

  1. NOT
  2. AND or NEAR
  3. OR

After precedence rules are applied, operators are processed left to right. You can use parentheses (( )) to override the normal precedence. For example, the first three queries are equivalent, but the fourth is not:

a AND b OR c

c OR a AND b

c OR (a AND b)

(c OR a) AND b

In the fourth query, the OR operator is evaluated first because the expression is enclosed in parentheses.

 




Copyright© 2000 Unicomp Laboratories, Inc. All rights reserved.
Site last updated : Friday, May 4, 2001 3:07 PM
For feedbacks and comments please send email to comments@unicomplabs.com.
46 Cain Drive, Brentwood NY 11717
Tel : (631) 231 - 1800 Fax : (631) 231 - 4842