Skip to content

Commit 3c725cf

Browse files
committed
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 8fbf910 commit 3c725cf

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
@@ -235,26 +235,10 @@ states that:
235235
* `news` must not be present
236236
* `quick` and `brown` are optional -- their presence increases the relevance
237237

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

259243
`((quick AND fox) OR (brown AND fox) OR fox) AND NOT news`::
260244

0 commit comments

Comments
 (0)