]> git.notmuchmail.org Git - notmuch/blob - doc/man7/notmuch-search-terms.rst
Merge branch 'release'
[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.  See
163 **notmuch-properties(7)** for more details.
164
165 Operators
166 ---------
167
168 In addition to individual terms, multiple terms can be combined with
169 Boolean operators (**and**, **or**, **not**, and **xor**). Each term
170 in the query will be implicitly connected by a logical AND if no
171 explicit operator is provided (except that terms with a common prefix
172 will be implicitly combined with OR).  The shorthand '-<term>' can be
173 used for 'not <term>' but unfortunately this does not work at the
174 start of an expression.  Parentheses can also be used to control the
175 combination of the Boolean operators, but will have to be protected
176 from interpretation by the shell, (such as by putting quotation marks
177 around any parenthesized expression).
178
179 In addition to the standard boolean operators, Xapian provides several
180 operators specific to text searching.
181
182 ::
183
184         notmuch search term1 NEAR term2
185
186 will return results where term1 is within 10 words of term2. The
187 threshold can be set like this:
188
189 ::
190
191         notmuch search term1 NEAR/2 term2
192
193 The search
194
195 ::
196
197         notmuch search term1 ADJ term2
198
199 will return results where term1 is within 10 words of term2, but in the
200 same order as in the query. The threshold can be set the same as with
201 NEAR:
202
203 ::
204
205         notmuch search term1 ADJ/7 term2
206
207
208 Stemming
209 --------
210
211 **Stemming** in notmuch means that these searches
212
213 ::
214
215         notmuch search detailed
216         notmuch search details
217         notmuch search detail
218
219 will all return identical results, because Xapian first "reduces" the
220 term to the common stem (here 'detail') and then performs the search.
221
222 There are two ways to turn this off: a search for a capitalized word
223 will be performed unstemmed, so that one can search for "John" and not
224 get results for "Johnson"; phrase searches are also unstemmed (see
225 below for details).  Stemming is currently only supported for
226 English. Searches for words in other languages will be performed unstemmed.
227
228 Wildcards
229 ---------
230
231 It is possible to use a trailing '\*' as a wildcard. A search for
232 'wildc\*' will match 'wildcard', 'wildcat', etc.
233
234
235 Boolean and Probabilistic Prefixes
236 ----------------------------------
237
238 Xapian (and hence notmuch) prefixes are either **boolean**, supporting
239 exact matches like "tag:inbox" or **probabilistic**, supporting a more
240 flexible **term** based searching. Certain **special** prefixes are
241 processed by notmuch in a way not strictly fitting either of Xapian's
242 built in styles. The prefixes currently supported by notmuch are as
243 follows.
244
245 Boolean
246    **tag:**, **id:**, **thread:**, **folder:**, **path:**, **property:**
247 Probabilistic
248   **to:**, **attachment:**, **mimetype:**
249 Special
250    **from:**, **query:**, **subject:**
251
252 Terms and phrases
253 -----------------
254
255 In general Xapian distinguishes between lists of terms and
256 **phrases**. Phrases are indicated by double quotes (but beware you
257 probably need to protect those from your shell) and insist that those
258 unstemmed words occur in that order. One useful, but initially
259 surprising feature is that the following are equivalent ways to write
260 the same phrase.
261
262 - "a list of words"
263 - a-list-of-words
264 - a/list/of/words
265 - a.list.of.words
266
267 Both parenthesised lists of terms and quoted phrases are ok with
268 probabilistic prefixes such as **to:**, **from:**, and **subject:**. In particular
269
270 ::
271
272    subject:(pizza free)
273
274 is equivalent to
275
276 ::
277
278    subject:pizza and subject:free
279
280 Both of these will match a subject "Free Delicious Pizza" while
281
282 ::
283
284    subject:"pizza free"
285
286 will not.
287
288 DATE AND TIME SEARCH
289 ====================
290
291 notmuch understands a variety of standard and natural ways of expressing
292 dates and times, both in absolute terms ("2012-10-24") and in relative
293 terms ("yesterday"). Any number of relative terms can be combined ("1
294 hour 25 minutes") and an absolute date/time can be combined with
295 relative terms to further adjust it. A non-exhaustive description of the
296 syntax supported for absolute and relative terms is given below.
297
298 The range expression
299 --------------------
300
301 date:<since>..<until>
302
303 The above expression restricts the results to only messages from <since>
304 to <until>, based on the Date: header.
305
306 <since> and <until> can describe imprecise times, such as "yesterday".
307 In this case, <since> is taken as the earliest time it could describe
308 (the beginning of yesterday) and <until> is taken as the latest time it
309 could describe (the end of yesterday). Similarly, date:january..february
310 matches from the beginning of January to the end of February.
311
312 date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The
313 expansion takes place before interpretation, and thus, for example,
314 date:monday..! matches from the beginning of Monday until the end of
315 Monday.
316 With **Xapian Field Processor** support (see below), non-range
317 date queries such as date:yesterday will work, but otherwise
318 will give unexpected results; if in doubt use date:yesterday..!
319
320 Currently, we do not support spaces in range expressions. You can
321 replace the spaces with '\_', or (in most cases) '-', or (in some cases)
322 leave the spaces out altogether. Examples in this man page use spaces
323 for clarity.
324
325 Open-ended ranges are supported (since Xapian 1.2.1), i.e. it's possible
326 to specify date:..<until> or date:<since>.. to not limit the start or
327 end time, respectively. Pre-1.2.1 Xapian does not report an error on
328 open ended ranges, but it does not work as expected either.
329
330 Relative date and time
331 ----------------------
332
333 [N\|number]
334 (years\|months\|weeks\|days\|hours\|hrs\|minutes\|mins\|seconds\|secs)
335 [...]
336
337 All refer to past, can be repeated and will be accumulated.
338
339 Units can be abbreviated to any length, with the otherwise ambiguous
340 single m being m for minutes and M for months.
341
342 Number can also be written out one, two, ..., ten, dozen, hundred.
343 Additionally, the unit may be preceded by "last" or "this" (e.g., "last
344 week" or "this month").
345
346 When combined with absolute date and time, the relative date and time
347 specification will be relative from the specified absolute date and
348 time.
349
350 Examples: 5M2d, two weeks
351
352 Supported absolute time formats
353 -------------------------------
354
355 -  H[H]:MM[:SS] [(am\|a.m.\|pm\|p.m.)]
356
357 -  H[H] (am\|a.m.\|pm\|p.m.)
358
359 -  HHMMSS
360
361 -  now
362
363 -  noon
364
365 -  midnight
366
367 -  Examples: 17:05, 5pm
368
369 Supported absolute date formats
370 -------------------------------
371
372 -  YYYY-MM[-DD]
373
374 -  DD-MM[-[YY]YY]
375
376 -  MM-YYYY
377
378 -  M[M]/D[D][/[YY]YY]
379
380 -  M[M]/YYYY
381
382 -  D[D].M[M][.[YY]YY]
383
384 -  D[D][(st\|nd\|rd\|th)] Mon[thname] [YYYY]
385
386 -  Mon[thname] D[D][(st\|nd\|rd\|th)] [YYYY]
387
388 -  Wee[kday]
389
390 Month names can be abbreviated at three or more characters.
391
392 Weekday names can be abbreviated at three or more characters.
393
394 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
395
396 Time zones
397 ----------
398
399 -  (+\|-)HH:MM
400
401 -  (+\|-)HH[MM]
402
403 Some time zone codes, e.g. UTC, EET.
404
405 XAPIAN FIELD PROCESSORS
406 =======================
407
408 Certain optional features of the notmuch query processor rely on the
409 presence of the Xapian field processor API. You can determine if your
410 notmuch was built against a sufficiently recent version of Xapian by running
411
412 ::
413
414   % notmuch config get built_with.field_processor
415
416 Currently the following features require field processor support:
417
418 - non-range date queries, e.g. "date:today"
419 - named queries e.g. "query:my_special_query"
420 - regular expression searches, e.g. "subject:/^\\[SPAM\\]/"
421
422 SEE ALSO
423 ========
424
425 **notmuch(1)**,
426 **notmuch-config(1)**,
427 **notmuch-count(1)**,
428 **notmuch-dump(1)**,
429 **notmuch-hooks(5)**,
430 **notmuch-insert(1)**,
431 **notmuch-new(1)**,
432 **notmuch-reindex(1)**,
433 **notmuch-properties(1)**,
434 ***notmuch-reply(1)**,
435 **notmuch-restore(1)**,
436 **notmuch-search(1)**,
437 ***notmuch-show(1)**,
438 **notmuch-tag(1)**