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 AND operator 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 word AND.
- Examples:
- To search for records that contain both the word Beta1 and
the phrase Beta2 test, use the following query:
Beta1 AND "Beta2 test"
- To search for records that contain the word Beta1,
the phrase Beta2 test, and 7.1,
use the following query:
Beta1 AND "Beta2 test" AND 7.1
The following query returns the same results:Beta1 && "Beta2 test" AND 7.1
- To search for records that contain both the word Beta1 and
the phrase Beta2 test, use the following query:
- +
- 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 Beta1 and
might contain Beta2, use the following query:
+Beta1 Beta2
- To search for records that must contain the word Beta1 and
might contain Beta2, use the following query:
- OR
- ||
- The OR operator 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 word OR.
- Example:
- To search for records that contain either the word Beta1 or
the phrase Beta2 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 Beta1 or
the phrase Beta2 test, use the following query:
- NOT
- The NOT operator excludes records that contain
the term or phrase following the NOT operator. This
is equivalent to a difference in sets.
- Example:
- To search for records that contain the word Beta1 but
not Beta2, use the following query:
Beta1 NOT Beta2
Attention: The NOT operator 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 Beta1 but
not Beta2, use the following query:
- -
- !
- 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 Beta1 but
not Beta2, use the following query:
Beta1 -Beta2
The following queries return the same results:-Beta2 Beta1
!Beta2 Beta1
- To search for records that contain the word Beta1 but
not Beta2, use the following query: