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