Boolean operators
Boolean operators allow terms to be combined through logic operators.
Lucene supports the following Boolean operators:
AND && + OR || NOT ! -Attention: The Lucene Boolean operators
AND, OR,
and NOT are case sensitive and must be written as
shown.- AND
- &&
- The
ANDoperator associates two terms or phrases and finds a matching record if both terms or phrases exist in a record. This is equivalent to the intersection of two sets. You can use the symbol&&in place of the wordAND.- Examples:
- To search for records that contain both the word
Beta1and the phraseBeta2 test, use the following query:Beta1 AND "Beta2 test" - To search for records that contain the word
Beta1, the phraseBeta2 test, and7.1, use the following query:Beta1 AND "Beta2 test" AND 7.1The following query returns the same results:Beta1 && "Beta2 test" AND 7.1
- To search for records that contain both the word
- +
- The
+operator, also known as the required operator, indicates that the term or phrase after the+operator exists somewhere in a field of a record.- Example:
- To search for records that must contain the word
Beta1and might containBeta2, use the following query:+Beta1 Beta2
- To search for records that must contain the word
- OR
- ||
- The
ORoperator associates two terms or phrases and finds a matching record if either of the terms or phrases exists in a record. This is equivalent to the union of two sets. You can use the symbol || in place of the wordOR.- Example:
- To search for records that contain either the word
Beta1or the phraseBeta2 test, use the following query:Beta1 OR "Beta2 test"The following query returns the same results:Beta1 || "Beta2 test"
- To search for records that contain either the word
- NOT
- The
NOToperator excludes records that contain the term or phrase following theNOToperator. This is equivalent to a difference in sets.- Example:
- To search for records that contain the word
Beta1but notBeta2, use the following query:Beta1 NOT Beta2
Attention: TheNOToperator cannot be used with just one term or phrase. For example, the following search will return no results:NOT Beta1- To search for records that contain the word
-- !
- The
-operator, also known as the prohibit operator, excludes records that contain the term or phrase after the symbol-. You can use the symbol!in place of the operator-.- Example:
- To search for records that contain the word
Beta1but notBeta2, use the following query:Beta1 -Beta2The following queries return the same results:-Beta2 Beta1!Beta2 Beta1
- To search for records that contain the word