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