]> git.notmuchmail.org Git - notmuch/blob - doc/man7/notmuch-search-terms.rst
Merge tag 0.28.4
[notmuch] / doc / man7 / notmuch-search-terms.rst
1 ====================
2 notmuch-search-terms
3 ====================
4
5 SYNOPSIS
6 ========
7
8 **notmuch** **count** [option ...] <*search-term*> ...
9
10 **notmuch** **dump** [--gzip] [--format=(batch-tag|sup)] [--output=<*file*>] [--] [<*search-term*> ...]
11
12 **notmuch** **reindex** [option ...] <*search-term*> ...
13
14 **notmuch** **search** [option ...] <*search-term*> ...
15
16 **notmuch** **show** [option ...] <*search-term*> ...
17
18 **notmuch** **tag** +<*tag*> ... -<*tag*> [--] <*search-term*> ...
19
20 DESCRIPTION
21 ===========
22
23 Several notmuch commands accept a common syntax for search terms.
24
25 The search terms can consist of free-form text (and quoted phrases)
26 which will match all messages that contain all of the given
27 terms/phrases in the body, the subject, or any of the sender or
28 recipient headers.
29
30 As a special case, a search string consisting of exactly a single
31 asterisk ("\*") will match all messages.
32
33 Search prefixes
34 ---------------
35
36 In addition to free text, the following prefixes can be used to force
37 terms to match against specific portions of an email, (where <brackets>
38 indicate user-supplied values).
39
40 If notmuch is built with **Xapian Field Processors** (see below) some
41 of the prefixes with <regex> forms can be also used to restrict the
42 results to those whose value matches a regular expression (see
43 **regex(7)**) delimited with //, for example::
44
45    notmuch search 'from:"/bob@.*[.]example[.]com/"'
46
47 body:<word-or-quoted-phrase>
48     Match terms in the body of messages.
49
50 from:<name-or-address> or from:/<regex>/
51     The **from:** prefix is used to match the name or address of
52     the sender of an email message.
53
54 to:<name-or-address>
55     The **to:** prefix is used to match the names or addresses of any
56     recipient of an email message, (whether To, Cc, or Bcc).
57
58 subject:<word-or-quoted-phrase> or subject:/<regex>/
59     Any term prefixed with **subject:** will match only text from the
60     subject of an email. Searching for a phrase in the subject is
61     supported by including quotation marks around the phrase,
62     immediately following **subject:**.
63
64 attachment:<word>
65     The **attachment:** prefix can be used to search for specific
66     filenames (or extensions) of attachments to email messages.
67
68 mimetype:<word>
69     The **mimetype:** prefix will be used to match text from the
70     content-types of MIME parts within email messages (as specified by
71     the sender).
72
73 tag:<tag> or tag:/<regex>/ or is:<tag> or is:/<regex>/
74     For **tag:** and **is:** valid tag values include **inbox** and
75     **unread** by default for new messages added by **notmuch new** as
76     well as any other tag values added manually with **notmuch tag**.
77
78 id:<message-id> or mid:<message-id> or mid:/<regex>/
79     For **id:** and **mid:**, message ID values are the literal
80     contents of the Message-ID: header of email messages, but without
81     the '<', '>' delimiters.
82
83 thread:<thread-id>
84     The **thread:** prefix can be used with the thread ID values that
85     are generated internally by notmuch (and do not appear in email
86     messages). These thread ID values can be seen in the first column
87     of output from **notmuch search**
88
89 thread:{<notmuch query>}
90     If notmuch is built with **Xapian Field Processors** (see below),
91     threads may be searched for indirectly by providing an arbitrary
92     notmuch query in **{}**. For example, the following returns
93     threads containing a message from mallory and one (not necessarily
94     the same message) with Subject containing the word "crypto".
95
96     ::
97
98        % notmuch search 'thread:"{from:mallory}" and thread:"{subject:crypto}"'
99
100     The performance of such queries can vary wildly. To understand
101     this, the user should think of the query **thread:{<something>}**
102     as expanding to all of the thread IDs which match **<something>**;
103     notmuch then performs a second search using the expanded query.
104
105 path:<directory-path> or path:<directory-path>/** or path:/<regex>/
106     The **path:** prefix searches for email messages that are in
107     particular directories within the mail store. The directory must
108     be specified relative to the top-level maildir (and without the
109     leading slash). By default, **path:** matches messages in the
110     specified directory only. The "/\*\*" suffix can be used to match
111     messages in the specified directory and all its subdirectories
112     recursively. **path:""** matches messages in the root of the mail
113     store and, likewise, **path:\*\*** matches all messages.
114
115     **path:** will find a message if *any* copy of that message is in
116     the specific directory.
117
118 folder:<maildir-folder> or folder:/<regex>/
119     The **folder:** prefix searches for email messages by maildir or
120     MH folder. For MH-style folders, this is equivalent to
121     **path:**. For maildir, this includes messages in the "new" and
122     "cur" subdirectories. The exact syntax for maildir folders depends
123     on your mail configuration. For maildir++, **folder:""** matches
124     the inbox folder (which is the root in maildir++), other folder
125     names always start with ".", and nested folders are separated by
126     "."s, such as **folder:.classes.topology**. For "file system"
127     maildir, the inbox is typically **folder:INBOX** and nested
128     folders are separated by slashes, such as
129     **folder:classes/topology**.
130
131     **folder:** will find a message if *any* copy of that message is
132     in the specific folder.
133
134 date:<since>..<until> or date:<date>
135     The **date:** prefix can be used to restrict the results to only
136     messages within a particular time range (based on the Date:
137     header).
138
139     See **DATE AND TIME SEARCH** below for details on the range
140     expression, and supported syntax for <since> and <until> date and
141     time expressions.
142
143     The time range can also be specified using timestamps without
144     including the date prefix using a syntax of:
145
146     <initial-timestamp>..<final-timestamp>
147
148     Each timestamp is a number representing the number of seconds
149     since 1970-01-01 00:00:00 UTC. Specifying a time range this way
150     is considered legacy and predates the date prefix.
151
152 lastmod:<initial-revision>..<final-revision>
153     The **lastmod:** prefix can be used to restrict the result by the
154     database revision number of when messages were last modified (tags
155     were added/removed or filenames changed). This is usually used in
156     conjunction with the ``--uuid`` argument to **notmuch search** to
157     find messages that have changed since an earlier query.
158
159 query:<name>
160     The **query:** prefix allows queries to refer to previously saved
161     queries added with **notmuch-config(1)**. Named queries are only
162     available if notmuch is built with **Xapian Field Processors**
163     (see below).
164
165 property:<key>=<value>
166     The **property:** prefix searches for messages with a particular
167     <key>=<value> property pair. Properties are used internally by
168     notmuch (and extensions) to add metadata to messages. A given key
169     can be present on a given message with several different values.
170     See **notmuch-properties(7)** for more details.
171
172 Operators
173 ---------
174
175 In addition to individual terms, multiple terms can be combined with
176 Boolean operators (**and**, **or**, **not**, and **xor**). Each term
177 in the query will be implicitly connected by a logical AND if no
178 explicit operator is provided (except that terms with a common prefix
179 will be implicitly combined with OR).  The shorthand '-<term>' can be
180 used for 'not <term>' but unfortunately this does not work at the
181 start of an expression.  Parentheses can also be used to control the
182 combination of the Boolean operators, but will have to be protected
183 from interpretation by the shell, (such as by putting quotation marks
184 around any parenthesized expression).
185
186 In addition to the standard boolean operators, Xapian provides several
187 operators specific to text searching.
188
189 ::
190
191         notmuch search term1 NEAR term2
192
193 will return results where term1 is within 10 words of term2. The
194 threshold can be set like this:
195
196 ::
197
198         notmuch search term1 NEAR/2 term2
199
200 The search
201
202 ::
203
204         notmuch search term1 ADJ term2
205
206 will return results where term1 is within 10 words of term2, but in the
207 same order as in the query. The threshold can be set the same as with
208 NEAR:
209
210 ::
211
212         notmuch search term1 ADJ/7 term2
213
214
215 Stemming
216 --------
217
218 **Stemming** in notmuch means that these searches
219
220 ::
221
222         notmuch search detailed
223         notmuch search details
224         notmuch search detail
225
226 will all return identical results, because Xapian first "reduces" the
227 term to the common stem (here 'detail') and then performs the search.
228
229 There are two ways to turn this off: a search for a capitalized word
230 will be performed unstemmed, so that one can search for "John" and not
231 get results for "Johnson"; phrase searches are also unstemmed (see
232 below for details).  Stemming is currently only supported for
233 English. Searches for words in other languages will be performed unstemmed.
234
235 Wildcards
236 ---------
237
238 It is possible to use a trailing '\*' as a wildcard. A search for
239 'wildc\*' will match 'wildcard', 'wildcat', etc.
240
241
242 Boolean and Probabilistic Prefixes
243 ----------------------------------
244
245 Xapian (and hence notmuch) prefixes are either **boolean**, supporting
246 exact matches like "tag:inbox" or **probabilistic**, supporting a more
247 flexible **term** based searching. Certain **special** prefixes are
248 processed by notmuch in a way not strictly fitting either of Xapian's
249 built in styles. The prefixes currently supported by notmuch are as
250 follows.
251
252 Boolean
253    **tag:**, **id:**, **thread:**, **folder:**, **path:**, **property:**
254 Probabilistic
255   **body:**, **to:**, **attachment:**, **mimetype:**
256 Special
257    **from:**, **query:**, **subject:**
258
259 Terms and phrases
260 -----------------
261
262 In general Xapian distinguishes between lists of terms and
263 **phrases**. Phrases are indicated by double quotes (but beware you
264 probably need to protect those from your shell) and insist that those
265 unstemmed words occur in that order. One useful, but initially
266 surprising feature is that the following are equivalent ways to write
267 the same phrase.
268
269 - "a list of words"
270 - a-list-of-words
271 - a/list/of/words
272 - a.list.of.words
273
274 Both parenthesised lists of terms and quoted phrases are ok with
275 probabilistic prefixes such as **to:**, **from:**, and **subject:**. In particular
276
277 ::
278
279    subject:(pizza free)
280
281 is equivalent to
282
283 ::
284
285    subject:pizza and subject:free
286
287 Both of these will match a subject "Free Delicious Pizza" while
288
289 ::
290
291    subject:"pizza free"
292
293 will not.
294
295 Quoting
296 -------
297
298 Double quotes are also used by the notmuch query parser to protect
299 boolean terms, regular expressions, or subqueries containing spaces or
300 other special characters, e.g.
301
302 ::
303
304    tag:"a tag"
305
306 ::
307
308    folder:"/^.*/(Junk|Spam)$/"
309
310 ::
311
312    thread:"{from:mallory and date:2009}"
313
314 As with phrases, you need to protect the double quotes from the shell
315 e.g.
316
317 ::
318
319    % notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
320    % notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
321
322 DATE AND TIME SEARCH
323 ====================
324
325 notmuch understands a variety of standard and natural ways of expressing
326 dates and times, both in absolute terms ("2012-10-24") and in relative
327 terms ("yesterday"). Any number of relative terms can be combined ("1
328 hour 25 minutes") and an absolute date/time can be combined with
329 relative terms to further adjust it. A non-exhaustive description of the
330 syntax supported for absolute and relative terms is given below.
331
332 The range expression
333 --------------------
334
335 date:<since>..<until>
336
337 The above expression restricts the results to only messages from <since>
338 to <until>, based on the Date: header.
339
340 <since> and <until> can describe imprecise times, such as "yesterday".
341 In this case, <since> is taken as the earliest time it could describe
342 (the beginning of yesterday) and <until> is taken as the latest time it
343 could describe (the end of yesterday). Similarly, date:january..february
344 matches from the beginning of January to the end of February.
345
346 If specifying a time range using timestamps in conjunction with the
347 date prefix, each timestamp must be preceded by @ (ASCII hex 40). As
348 above, each timestamp is a number representing the number of seconds
349 since 1970-01-01 00:00:00 UTC. For example:
350
351     date:@<initial-timestamp>..@<final-timestamp>
352
353 date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The
354 expansion takes place before interpretation, and thus, for example,
355 date:monday..! matches from the beginning of Monday until the end of
356 Monday.
357 With **Xapian Field Processor** support (see below), non-range
358 date queries such as date:yesterday will work, but otherwise
359 will give unexpected results; if in doubt use date:yesterday..!
360
361 Currently, we do not support spaces in range expressions. You can
362 replace the spaces with '\_', or (in most cases) '-', or (in some cases)
363 leave the spaces out altogether. Examples in this man page use spaces
364 for clarity.
365
366 Open-ended ranges are supported (since Xapian 1.2.1), i.e. it's possible
367 to specify date:..<until> or date:<since>.. to not limit the start or
368 end time, respectively. Pre-1.2.1 Xapian does not report an error on
369 open ended ranges, but it does not work as expected either.
370
371 Relative date and time
372 ----------------------
373
374 [N\|number]
375 (years\|months\|weeks\|days\|hours\|hrs\|minutes\|mins\|seconds\|secs)
376 [...]
377
378 All refer to past, can be repeated and will be accumulated.
379
380 Units can be abbreviated to any length, with the otherwise ambiguous
381 single m being m for minutes and M for months.
382
383 Number can also be written out one, two, ..., ten, dozen, hundred.
384 Additionally, the unit may be preceded by "last" or "this" (e.g., "last
385 week" or "this month").
386
387 When combined with absolute date and time, the relative date and time
388 specification will be relative from the specified absolute date and
389 time.
390
391 Examples: 5M2d, two weeks
392
393 Supported absolute time formats
394 -------------------------------
395
396 -  H[H]:MM[:SS] [(am\|a.m.\|pm\|p.m.)]
397
398 -  H[H] (am\|a.m.\|pm\|p.m.)
399
400 -  HHMMSS
401
402 -  now
403
404 -  noon
405
406 -  midnight
407
408 -  Examples: 17:05, 5pm
409
410 Supported absolute date formats
411 -------------------------------
412
413 -  YYYY-MM[-DD]
414
415 -  DD-MM[-[YY]YY]
416
417 -  MM-YYYY
418
419 -  M[M]/D[D][/[YY]YY]
420
421 -  M[M]/YYYY
422
423 -  D[D].M[M][.[YY]YY]
424
425 -  D[D][(st\|nd\|rd\|th)] Mon[thname] [YYYY]
426
427 -  Mon[thname] D[D][(st\|nd\|rd\|th)] [YYYY]
428
429 -  Wee[kday]
430
431 Month names can be abbreviated at three or more characters.
432
433 Weekday names can be abbreviated at three or more characters.
434
435 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
436
437 Time zones
438 ----------
439
440 -  (+\|-)HH:MM
441
442 -  (+\|-)HH[MM]
443
444 Some time zone codes, e.g. UTC, EET.
445
446 XAPIAN FIELD PROCESSORS
447 =======================
448
449 Certain optional features of the notmuch query processor rely on the
450 presence of the Xapian field processor API. You can determine if your
451 notmuch was built against a sufficiently recent version of Xapian by running
452
453 ::
454
455   % notmuch config get built_with.field_processor
456
457 Currently the following features require field processor support:
458
459 - non-range date queries, e.g. "date:today"
460 - named queries e.g. "query:my_special_query"
461 - regular expression searches, e.g. "subject:/^\\[SPAM\\]/"
462 - thread subqueries, e.g. "thread:{from:bob}"
463
464 SEE ALSO
465 ========
466
467 **notmuch(1)**,
468 **notmuch-config(1)**,
469 **notmuch-count(1)**,
470 **notmuch-dump(1)**,
471 **notmuch-hooks(5)**,
472 **notmuch-insert(1)**,
473 **notmuch-new(1)**,
474 **notmuch-reindex(1)**,
475 **notmuch-properties(1)**,
476 ***notmuch-reply(1)**,
477 **notmuch-restore(1)**,
478 **notmuch-search(1)**,
479 ***notmuch-show(1)**,
480 **notmuch-tag(1)**