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