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