Order of Precedence
Overview
Processing search queries in a specific order of precedence ensures complex searches return consistent results, even when multiple operators are combined. The Docwize search engine first evaluates grouped expressions (parentheses) and exact phrases, then applies negations, intersections (AND), and finally unions (OR). Parentheses can always be used to explicitly control evaluation order.
Priority Order
| Priority | Operator | Description | Example |
|---|---|---|---|
| 1 | () | Groups expressions and forces evaluation order | (invoice OR receipt) AND approved |
| 2 | " " | Treats text as an exact phrase | "project summary" AND report |
| 3 | ! or NOT | Excludes terms or phrases | report !draft |
| 4 | && or AND | Requires all terms | project AND report |
| 5 | || or OR | Requires any term | invoice OR receipt |
Precedence Examples in Practice
| Operator Type | Description | Example Query | Evaluation & Result |
|---|---|---|---|
Parentheses ( ) | Anything inside parentheses is evaluated first. | (invoice OR receipt) AND approved | Returns results containing approved and either invoice or receipt. |
Phrase Matching " " | Quoted phrases bind words together exactly. | "project summary" AND report | Finds results containing the exact phrase project summary plus report anywhere. |
| NOT / ! (Negation) | Negations are applied before intersections. | report AND !draft | Returns documents with report but excluding draft. |
| AND / && (Intersection) | The default operator in Docwize. | project report | Interpreted as project AND report — both terms must appear. |
| || or OR | OR has the lowest precedence, combining results from either side. | invoice OR receipt AND approved | Evaluated as invoice OR (receipt AND approved). |
Precedence Error Examples
These examples show how misunderstanding operator precedence (the order in which Docwize processes search terms) can lead to unexpected results — especially when combining AND, OR, and NOT.
1. The Ambiguous OR
| Scenario | Incorrect Query | User’s Intent | Actual Evaluation | What Goes Wrong | The Fix |
|---|---|---|---|---|---|
| A user wants to find all final documents that are either a report or a summary. | report OR summary AND final | (report OR summary) AND final | report OR (summary AND final) | The query returns: - All documents containing report (even if they aren't final). - All documents containing both summary AND final. This is broader than intended. | (report OR summary) AND final |
2. The Ambiguous NOT
| Scenario | Incorrect Query | User’s Intent | Actual Evaluation | What Goes Wrong | The Fix |
|---|---|---|---|---|---|
| A user wants to find all invoices but exclude any that are drafts or archived. | invoice AND NOT draft OR archived | invoice AND NOT (draft OR archived) | invoice AND (NOT draft) OR archived | - AND and NOT bind more tightly than OR. - Returns documents with invoice but not draft. - Also includes all archived documents — even non-invoices. | invoice AND NOT (draft OR archived)or invoice AND !draft AND !archived |
3. The Unquoted Phrase
| Scenario | Incorrect Query | User’s Intent | Actual Evaluation | What Goes Wrong | The Fix |
|---|---|---|---|---|---|
| A user wants documents containing the exact phrase "project status report" from 2024. | project status report AND year:2024 | "project status report" AND year:2024 | (project AND status AND report) AND year:2024 | - Finds project, status, and report anywhere (not necessarily together). - Includes many irrelevant results. | "project status report" AND year:2024 |