Clarify docs about boolean operator precedence. (#30808)

Unfortunately, the classic queryparser does not honor the usual precedence
rules of boolean operators. See
https://issues.apache.org/jira/browse/LUCENE-3674.
This commit is contained in:
Adrien Grand 2018-06-05 08:59:17 +02:00 committed by GitHub
parent 21fe6159d4
commit 984523dda9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -233,26 +233,10 @@ states that:
* `news` must not be present * `news` must not be present
* `quick` and `brown` are optional -- their presence increases the relevance * `quick` and `brown` are optional -- their presence increases the relevance
The familiar operators `AND`, `OR` and `NOT` (also written `&&`, `||` and `!`) The familiar boolean operators `AND`, `OR` and `NOT` (also written `&&`, `||`
are also supported. However, the effects of these operators can be more and `!`) are also supported but beware that they do not honor the usual
complicated than is obvious at first glance. `NOT` takes precedence over precedence rules, so parentheses should be used whenever multiple operators are
`AND`, which takes precedence over `OR`. While the `+` and `-` only affect used together. For instance the previous query could be rewritten as:
the term to the right of the operator, `AND` and `OR` can affect the terms to
the left and right.
****
Rewriting the above query using `AND`, `OR` and `NOT` demonstrates the
complexity:
`quick OR brown AND fox AND NOT news`::
This is incorrect, because `brown` is now a required term.
`(quick OR brown) AND fox AND NOT news`::
This is incorrect because at least one of `quick` or `brown` is now required
and the search for those terms would be scored differently from the original
query.
`((quick AND fox) OR (brown AND fox) OR fox) AND NOT news`:: `((quick AND fox) OR (brown AND fox) OR fox) AND NOT news`::