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