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