Skip to main content

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

PriorityOperatorDescriptionExample
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 NOTExcludes terms or phrasesreport !draft
4&& or ANDRequires all termsproject AND report
5|| or ORRequires any terminvoice OR receipt

Precedence Examples in Practice

Operator TypeDescriptionExample QueryEvaluation & Result
Parentheses ( )Anything inside parentheses is evaluated first.(invoice OR receipt) AND approvedReturns results containing approved and either invoice or receipt.
Phrase Matching " "Quoted phrases bind words together exactly."project summary" AND reportFinds results containing the exact phrase project summary plus report anywhere.
NOT / ! (Negation)Negations are applied before intersections.report AND !draftReturns documents with report but excluding draft.
AND / && (Intersection)The default operator in Docwize.project reportInterpreted as project AND report — both terms must appear.
|| or OROR has the lowest precedence, combining results from either side.invoice OR receipt AND approvedEvaluated 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

ScenarioIncorrect QueryUser’s IntentActual EvaluationWhat Goes WrongThe 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 finalreport 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

ScenarioIncorrect QueryUser’s IntentActual EvaluationWhat Goes WrongThe Fix
A user wants to find all invoices but exclude any that are drafts or archived.invoice AND NOT draft OR archivedinvoice 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

ScenarioIncorrect QueryUser’s IntentActual EvaluationWhat Goes WrongThe 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