1 .. _notmuch-search-terms(7):
10 **notmuch** **count** [option ...] <*search-term*> ...
12 **notmuch** **dump** [--gzip] [--format=(batch-tag|sup)] [--output=<*file*>] [--] [<*search-term*> ...]
14 **notmuch** **reindex** [option ...] <*search-term*> ...
16 **notmuch** **search** [option ...] <*search-term*> ...
18 **notmuch** **show** [option ...] <*search-term*> ...
20 **notmuch** **tag** +<*tag*> ... -<*tag*> [--] <*search-term*> ...
25 Several notmuch commands accept a common syntax for search terms.
27 The search terms can consist of free-form text (and quoted phrases)
28 which will match all messages that contain all of the given
29 terms/phrases in the body, the subject, or any of the sender or
32 As a special case, a search string consisting of exactly a single
33 asterisk ("\*") will match all messages.
38 In addition to free text, the following prefixes can be used to force
39 terms to match against specific portions of an email, (where <brackets>
40 indicate user-supplied values).
42 Some of the prefixes with <regex> forms can be also used to restrict
43 the results to those whose value matches a regular expression (see
44 :manpage:`regex(7)`) delimited with //, for example::
46 notmuch search 'from:"/bob@.*[.]example[.]com/"'
48 body:<word-or-quoted-phrase>
49 Match terms in the body of messages.
51 from:<name-or-address> or from:/<regex>/
52 The **from:** prefix is used to match the name or address of
53 the sender of an email message.
56 The **to:** prefix is used to match the names or addresses of any
57 recipient of an email message, (whether To, Cc, or Bcc).
59 subject:<word-or-quoted-phrase> or subject:/<regex>/
60 Any term prefixed with **subject:** will match only text from the
61 subject of an email. Searching for a phrase in the subject is
62 supported by including quotation marks around the phrase,
63 immediately following **subject:**.
66 The **attachment:** prefix can be used to search for specific
67 filenames (or extensions) of attachments to email messages.
70 The **mimetype:** prefix will be used to match text from the
71 content-types of MIME parts within email messages (as specified by
74 tag:<tag> or tag:/<regex>/ or is:<tag> or is:/<regex>/
75 For **tag:** and **is:** valid tag values include **inbox** and
76 **unread** by default for new messages added by
77 :any:`notmuch-new(1)` as well as any other tag values added
78 manually with :any:`notmuch-tag(1)`.
80 id:<message-id> or mid:<message-id> or mid:/<regex>/
81 For **id:** and **mid:**, message ID values are the literal
82 contents of the Message-ID: header of email messages, but without
83 the '<', '>' delimiters.
86 The **thread:** prefix can be used with the thread ID values that
87 are generated internally by notmuch (and do not appear in email
88 messages). These thread ID values can be seen in the first column
89 of output from :any:`notmuch-search(1)`
91 thread:{<notmuch query>}
92 Threads may be searched for indirectly by providing an arbitrary
93 notmuch query in **{}**. For example, the following returns
94 threads containing a message from mallory and one (not necessarily
95 the same message) with Subject containing the word "crypto".
99 % notmuch search 'thread:"{from:mallory}" and thread:"{subject:crypto}"'
101 The performance of such queries can vary wildly. To understand
102 this, the user should think of the query **thread:{<something>}**
103 as expanding to all of the thread IDs which match **<something>**;
104 notmuch then performs a second search using the expanded query.
106 path:<directory-path> or path:<directory-path>/** or path:/<regex>/
107 The **path:** prefix searches for email messages that are in
108 particular directories within the mail store. The directory must
109 be specified relative to the top-level maildir (and without the
110 leading slash). By default, **path:** matches messages in the
111 specified directory only. The "/\*\*" suffix can be used to match
112 messages in the specified directory and all its subdirectories
113 recursively. **path:""** matches messages in the root of the mail
114 store and, likewise, **path:\*\*** matches all messages.
116 **path:** will find a message if *any* copy of that message is in
117 the specific directory.
119 folder:<maildir-folder> or folder:/<regex>/
120 The **folder:** prefix searches for email messages by maildir or
121 MH folder. For MH-style folders, this is equivalent to
122 **path:**. For maildir, this includes messages in the "new" and
123 "cur" subdirectories. The exact syntax for maildir folders depends
124 on your mail configuration. For maildir++, **folder:""** matches
125 the inbox folder (which is the root in maildir++), other folder
126 names always start with ".", and nested folders are separated by
127 "."s, such as **folder:.classes.topology**. For "file system"
128 maildir, the inbox is typically **folder:INBOX** and nested
129 folders are separated by slashes, such as
130 **folder:classes/topology**.
132 **folder:** will find a message if *any* copy of that message is
133 in the specific folder.
135 date:<since>..<until> or date:<date>
136 The **date:** prefix can be used to restrict the results to only
137 messages within a particular time range (based on the Date:
140 See **DATE AND TIME SEARCH** below for details on the range
141 expression, and supported syntax for <since> and <until> date and
144 The time range can also be specified using timestamps without
145 including the date prefix using a syntax of:
147 <initial-timestamp>..<final-timestamp>
149 Each timestamp is a number representing the number of seconds
150 since 1970-01-01 00:00:00 UTC. Specifying a time range this way
151 is considered legacy and predates the date prefix.
153 lastmod:<initial-revision>..<final-revision>
154 The **lastmod:** prefix can be used to restrict the result by the
155 database revision number of when messages were last modified (tags
156 were added/removed or filenames changed). This is usually used in
157 conjunction with the ``--uuid`` argument to
158 :any:`notmuch-search(1)` to find messages that have changed since
162 The **query:** prefix allows queries to refer to previously saved
163 queries added with :any:`notmuch-config(1)`.
165 property:<key>=<value>
166 The **property:** prefix searches for messages with a particular
167 <key>=<value> property pair. Properties are used internally by
168 notmuch (and extensions) to add metadata to messages. A given key
169 can be present on a given message with several different values.
170 See :any:`notmuch-properties(7)` for more details.
172 User defined prefixes are also supported, see :any:`notmuch-config(1)` for
178 In addition to individual terms, multiple terms can be combined with
179 Boolean operators (**and**, **or**, **not**, and **xor**). Each term
180 in the query will be implicitly connected by a logical AND if no
181 explicit operator is provided (except that terms with a common prefix
182 will be implicitly combined with OR). The shorthand '-<term>' can be
183 used for 'not <term>' but unfortunately this does not work at the
184 start of an expression. Parentheses can also be used to control the
185 combination of the Boolean operators, but will have to be protected
186 from interpretation by the shell, (such as by putting quotation marks
187 around any parenthesized expression).
189 In addition to the standard boolean operators, Xapian provides several
190 operators specific to text searching.
194 notmuch search term1 NEAR term2
196 will return results where term1 is within 10 words of term2. The
197 threshold can be set like this:
201 notmuch search term1 NEAR/2 term2
207 notmuch search term1 ADJ term2
209 will return results where term1 is within 10 words of term2, but in the
210 same order as in the query. The threshold can be set the same as with
215 notmuch search term1 ADJ/7 term2
221 **Stemming** in notmuch means that these searches
225 notmuch search detailed
226 notmuch search details
227 notmuch search detail
229 will all return identical results, because Xapian first "reduces" the
230 term to the common stem (here 'detail') and then performs the search.
232 There are two ways to turn this off: a search for a capitalized word
233 will be performed unstemmed, so that one can search for "John" and not
234 get results for "Johnson"; phrase searches are also unstemmed (see
235 below for details). Stemming is currently only supported for
236 English. Searches for words in other languages will be performed unstemmed.
241 It is possible to use a trailing '\*' as a wildcard. A search for
242 'wildc\*' will match 'wildcard', 'wildcat', etc.
245 Boolean and Probabilistic Prefixes
246 ----------------------------------
248 Xapian (and hence notmuch) prefixes are either **boolean**, supporting
249 exact matches like "tag:inbox" or **probabilistic**, supporting a more
250 flexible **term** based searching. Certain **special** prefixes are
251 processed by notmuch in a way not strictly fitting either of Xapian's
252 built in styles. The prefixes currently supported by notmuch are as
256 **tag:**, **id:**, **thread:**, **folder:**, **path:**, **property:**
258 **body:**, **to:**, **attachment:**, **mimetype:**
260 **from:**, **query:**, **subject:**
265 In general Xapian distinguishes between lists of terms and
266 **phrases**. Phrases are indicated by double quotes (but beware you
267 probably need to protect those from your shell) and insist that those
268 unstemmed words occur in that order. One useful, but initially
269 surprising feature is that the following are equivalent ways to write
277 Both parenthesised lists of terms and quoted phrases are ok with
278 probabilistic prefixes such as **to:**, **from:**, and **subject:**. In particular
288 subject:pizza and subject:free
290 Both of these will match a subject "Free Delicious Pizza" while
301 Double quotes are also used by the notmuch query parser to protect
302 boolean terms, regular expressions, or subqueries containing spaces or
303 other special characters, e.g.
311 folder:"/^.*/(Junk|Spam)$/"
315 thread:"{from:mallory and date:2009}"
317 As with phrases, you need to protect the double quotes from the shell
322 % notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
323 % notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
328 notmuch understands a variety of standard and natural ways of expressing
329 dates and times, both in absolute terms ("2012-10-24") and in relative
330 terms ("yesterday"). Any number of relative terms can be combined ("1
331 hour 25 minutes") and an absolute date/time can be combined with
332 relative terms to further adjust it. A non-exhaustive description of the
333 syntax supported for absolute and relative terms is given below.
338 date:<since>..<until>
340 The above expression restricts the results to only messages from <since>
341 to <until>, based on the Date: header.
343 <since> and <until> can describe imprecise times, such as "yesterday".
344 In this case, <since> is taken as the earliest time it could describe
345 (the beginning of yesterday) and <until> is taken as the latest time it
346 could describe (the end of yesterday). Similarly, date:january..february
347 matches from the beginning of January to the end of February.
349 If specifying a time range using timestamps in conjunction with the
350 date prefix, each timestamp must be preceded by @ (ASCII hex 40). As
351 above, each timestamp is a number representing the number of seconds
352 since 1970-01-01 00:00:00 UTC. For example:
354 date:@<initial-timestamp>..@<final-timestamp>
356 Currently, spaces in range expressions are not supported. You can
357 replace the spaces with '\_', or (in most cases) '-', or (in some cases)
358 leave the spaces out altogether. Examples in this man page use spaces
361 Open-ended ranges are supported. I.e. it's possible to specify
362 date:..<until> or date:<since>.. to not limit the start or
363 end time, respectively.
368 date:<expr> works as a shorthand for date:<expr>..<expr>.
369 For example, date:monday matches from the beginning of Monday until
372 Relative date and time
373 ----------------------
376 (years\|months\|weeks\|days\|hours\|hrs\|minutes\|mins\|seconds\|secs)
379 All refer to past, can be repeated and will be accumulated.
381 Units can be abbreviated to any length, with the otherwise ambiguous
382 single m being m for minutes and M for months.
384 Number can also be written out one, two, ..., ten, dozen, hundred.
385 Additionally, the unit may be preceded by "last" or "this" (e.g., "last
386 week" or "this month").
388 When combined with absolute date and time, the relative date and time
389 specification will be relative from the specified absolute date and
392 Examples: 5M2d, two weeks
394 Supported absolute time formats
395 -------------------------------
397 - H[H]:MM[:SS] [(am\|a.m.\|pm\|p.m.)]
399 - H[H] (am\|a.m.\|pm\|p.m.)
409 - Examples: 17:05, 5pm
411 Supported absolute date formats
412 -------------------------------
426 - D[D][(st\|nd\|rd\|th)] Mon[thname] [YYYY]
428 - Mon[thname] D[D][(st\|nd\|rd\|th)] [YYYY]
432 Month names can be abbreviated at three or more characters.
434 Weekday names can be abbreviated at three or more characters.
436 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
445 Some time zone codes, e.g. UTC, EET.
451 :any:`notmuch-config(1)`,
452 :any:`notmuch-count(1)`,
453 :any:`notmuch-dump(1)`,
454 :any:`notmuch-hooks(5)`,
455 :any:`notmuch-insert(1)`,
456 :any:`notmuch-new(1)`,
457 :any:`notmuch-properties(7)`,
458 :any:`notmuch-reindex(1)`,
459 :any:`notmuch-reply(1)`,
460 :any:`notmuch-restore(1)`,
461 :any:`notmuch-search(1)`,
462 :any:`notmuch-show(1)`,
463 :any:`notmuch-tag(1)`