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