Skip to content

Commit 984523d

Browse files
authored
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.
1 parent 21fe615 commit 984523d

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

docs/reference/query-dsl/query-string-syntax.asciidoc

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,10 @@ states that:
233233
* `news` must not be present
234234
* `quick` and `brown` are optional -- their presence increases the relevance
235235

236-
The familiar operators `AND`, `OR` and `NOT` (also written `&&`, `||` and `!`)
237-
are also supported. However, the effects of these operators can be more
238-
complicated than is obvious at first glance. `NOT` takes precedence over
239-
`AND`, which takes precedence over `OR`. While the `+` and `-` only affect
240-
the term to the right of the operator, `AND` and `OR` can affect the terms to
241-
the left and right.
242-
243-
****
244-
Rewriting the above query using `AND`, `OR` and `NOT` demonstrates the
245-
complexity:
246-
247-
`quick OR brown AND fox AND NOT news`::
248-
249-
This is incorrect, because `brown` is now a required term.
250-
251-
`(quick OR brown) AND fox AND NOT news`::
252-
253-
This is incorrect because at least one of `quick` or `brown` is now required
254-
and the search for those terms would be scored differently from the original
255-
query.
236+
The familiar boolean operators `AND`, `OR` and `NOT` (also written `&&`, `||`
237+
and `!`) are also supported but beware that they do not honor the usual
238+
precedence rules, so parentheses should be used whenever multiple operators are
239+
used together. For instance the previous query could be rewritten as:
256240

257241
`((quick AND fox) OR (brown AND fox) OR fox) AND NOT news`::
258242

0 commit comments

Comments
 (0)