A search query for DEVONthink's databases. One or more criteria evaluated left to right. Default boolean is AND. Bare terms (no prefix) match all string fields and must appear at the start.

## Boolean Operators

Precedence (high→low): `()` > `"phrases"` / hyphens > `BEFORE`/`AFTER`/`NEAR` (with optional `NOT`) > `NOT` > `AND`/`OR`/`XOR`.

| Syntax | Meaning |
|---|---|
| `term1 AND term2` | Both required (implicit default) |
| `term1 OR term2` | Either one |
| `term1 XOR term2` | Exactly one |
| `NOT term` | Excludes term |
| `"term1 term2"` | Exact phrase |
| `term1 OPT term2` | term2 optional but boosts ranking |
| `term1 NEAR term2` | Within 10 words |
| `term1 NEAR/n term2` | Within n words |
| `term1 BEFORE/n term2` | term1 at most n words before term2 |
| `term1 AFTER/n term2` | term1 at most n words after term2 |
| `~term` | Contains term as substring within a word |

## Wildcards (only with `:` operator)

`?` = one char, `*` = zero or more, `[a-z]` = range, `[abc]` = set, `[^abc]` = not in set. Regex NOT supported.

## Prefix Operators

### String Operators

| Op | Meaning | Wildcards |
|---|---|---|
| `:` | matches | yes |
| `:!` | does not match | yes |
| `==` | exact match | no |
| `!=` | is not | no |
| `:<` | begins with | no |
| `:>` | ends with | no |
| `:~` | contains substring | no |

### Numeric Operators

`==`, `!=`, `<`, `<=`, `>`, `>=`, and range `:low-high` (inclusive).

### Date Operators

`<`, `<=`, `>`, `>=` with dates (ISO 8601 `YYYY-MM-DD` recommended, time optional). Named periods with `:` / `:!`: `Today`, `Yesterday`, `This Week`, `Last Week`, `This Month`, `Last Month`, `This Quarter`, `Last Quarter`, `This Year`, `Last Year`. Recency: `:#ndays` / `:!#ndays` (e.g. `opened:#7days`). Weekday names NOT supported.

## Search Prefixes

### Text & Metadata

`text` (body), `metadata` (all metadata combined), `name`, `filename`, `extension` (also `any`), `url`, `comment`, `aliases`, `tags` (semicolon-separated: `tags:sync; methods`).

### Document Metadata

`docAuthors`, `docAuthorEmailAddresses`, `docRecipients`, `docRecipientEmailAddresses`, `docTitle`, `docComment`, `docSubject`, `docHeadline`, `docDescription`, `docKeywords`, `docOrganization`, `docCopyright`, `docAlbum`, `docComposer`, `docCreator`, `docProducer`.

### Numeric Properties

`width`, `height` (points), `length` (pages or seconds), `duration` (seconds), `size` (bytes; supports KB/MB/GB), `wordcount`, `charactercount`, `hits`, `rating` (0–5), `label` (0–7 or name).

### Kind

`kind:` values: `document`, `group`, `smartgroup`, `tag`, `ordinarytag`, `grouptag`, `text`, `rtf`, `formattednote`, `markdown`, `html`, `webarchive`, `xmlfile`, `propertylist`, `image`, `pdf`, `pdf+text`, `quicktime`, `video`, `audio`, `bookmark`, `feed`, `news`, `script`, `sheet`, `email`, `other`. Use `kind:document` to exclude groups/tags/smart groups when searching for files.

### Date Prefixes

`creationDate` / `created`, `modificationDate` / `modified`, `additionDate` / `added`, `openingDate` / `opened`, `dueDate` / `due`.

### Item State

`item:<state>` / `item:!<state>`: `replicated`, `duplicated`, `indexed`, `pending`, `tagged`, `aliases`, `annotation`, `comment`, `data`, `metadata`, `reminder`, `script`, `thumbnail`, `url`, `flagged`, `unflagged`, `read`, `unread`, `locked`, `unlocked`.

### Miscellaneous

`md_attachments`, `md_annotationcount`, `md_encrypted`, `md_incomingItemLinkCount`, `md_outgoingItemLinkCount`, `md_language`, `md_country`, `md_zipcode`, `md_area`, `md_locality`.

### Custom Metadata

Prefix = `md` + attribute name in lowercase, spaces removed (e.g. "Total Cost" → `mdtotalcost`).

## Sub-Criteria

`{ }` with `any:` (OR) or `all:` (AND, default): `any: name:test {any: tags:blue; red}`.

## Hyphenation

`word1-word2` / `word1_word2` → `word1word2 OR "word1 word2"`. Dots in abbreviations: `u.s.a` → `"u s a" OR usa`.

## Examples

```
kind:pdf tags:invoice created>=2024-01-01 created<2025-01-01
item:flagged item:unread
report kind:document modified:This Week
kind:pdf md_annotationcount>0
docAuthors:Smith rating>=4
item:!tagged added:#30days
Paracetamol NEAR (~effect OR impact) AND ((side OR second*) NEAR/2 ~effect)
```