Precedence Examples
Table 1 Query Expression Precedence Examples
| Query Expression | Order of Evaluation |
|---|---|
| w1 | w2 & w3 | (w1) | (w2 & w3) |
| w1 & w2 | w3 | (w1 & w2) | w3 |
| ?w1, w2 | w3 & w4 | (?w1), (w2 | (w3 & w4)) |
| abc = def ghi & jkl = mno | ((abc = def) ghi) & (jkl=mno) |
| dog and cat WITHIN body | dog and (cat WITHIN body) |
In the first example, because AND has a higher precedence than OR, the query returns all documents that contain w1 and all documents that contain both w2 and w3.
In the second example, the query returns all documents that contain both w1 and w2 and all documents that contain w3.
In the third example, the fuzzy operator is first applied to w1, then the AND operator is applied to arguments w3 and w4, then the OR operator is applied to term w2 and the results of the AND operation, and finally, the score from the fuzzy operation on w1 is added to the score from the OR operation.
The fourth example shows that the equivalence operator has higher precedence than the AND operator.
The fifth example shows that the AND operator has lower precedence than the WITHIN operator.