1 <h1>NOTMUCH-SEARCH-TERMS(7)</h1>
5 notmuch-search-terms - syntax for notmuch queries
10 <b>notmuch</b> <b>count</b> [option ...] <<u>search-term</u>> ...
12 <b>notmuch</b> <b>dump</b> [--format=(batch-tag|sup)] [--] [--output=<<u>file</u>>] [--]
13 [<<u>search-term</u>> ...]
15 <b>notmuch</b> <b>reindex</b> [option ...] <<u>search-term</u>> ...
17 <b>notmuch</b> <b>search</b> [option ...] <<u>search-term</u>> ...
19 <b>notmuch</b> <b>show</b> [option ...] <<u>search-term</u>> ...
21 <b>notmuch</b> <b>tag</b> +<<u>tag</u>> ... -<<u>tag</u>> [--] <<u>search-term</u>> ...
26 Several notmuch commands accept a common syntax for search terms.
28 The search terms can consist of free-form text (and quoted phrases)
29 which will match all messages that contain all of the given
30 terms/phrases in the body, the subject, or any of the sender or recipi‐
33 As a special case, a search string consisting of exactly a single
34 asterisk ("*") will match all messages.
37 <h3> Search prefixes</h3>
39 In addition to free text, the following prefixes can be used to force
40 terms to match against specific portions of an email, (where <brackets>
41 indicate user-supplied values).
43 If notmuch is built with <b>Xapian</b> <b>Field</b> <b>Processors</b> (see below) some of
44 the prefixes with <regex> forms can be also used to restrict the
45 results to those whose value matches a regular expression (see
46 <b>regex</b>(7)) delimited with //, for example:
48 notmuch search 'from:/bob@.*[.]example[.]com/'
50 <b>from:<name-or-address></b> <b>or</b> <b>from:/<regex>/</b>
51 The <b>from:</b> prefix is used to match the name or address of the
52 sender of an email message.
54 <b>to:<name-or-address></b>
55 The <b>to:</b> prefix is used to match the names or addresses of any
56 recipient of an email message, (whether To, Cc, or Bcc).
58 <b>subject:<word-or-quoted-phrase></b> <b>or</b> <b>subject:/<regex>/</b>
59 Any term prefixed with <b>subject:</b> will match only text from the
60 subject of an email. Searching for a phrase in the subject is
61 supported by including quotation marks around the phrase, imme‐
62 diately following <b>subject:</b>.
64 <b>attachment:<word></b>
65 The <b>attachment:</b> prefix can be used to search for specific file‐
66 names (or extensions) of attachments to email messages.
68 <b>mimetype:<word></b>
69 The <b>mimetype:</b> prefix will be used to match text from the con‐
70 tent-types of MIME parts within email messages (as specified by
73 <b>tag:<tag></b> <b>or</b> <b>tag:/<regex>/</b> <b>or</b> <b>is:<tag></b> <b>or</b> <b>is:/<regex>/</b>
74 For <b>tag:</b> and <b>is:</b> valid tag values include <b>inbox</b> and <b>unread</b> by
75 default for new messages added by <b>notmuch</b> <b>new</b> as well as any
76 other tag values added manually with <b>notmuch</b> <b>tag</b>.
78 <b>id:<message-id></b> <b>or</b> <b>mid:<message-id></b> <b>or</b> <b>mid:/<regex>/</b>
79 For <b>id:</b> and <b>mid:</b>, message ID values are the literal contents of
80 the Message-ID: header of email messages, but without the '<',
81 '>' delimiters.
83 <b>thread:<thread-id></b>
84 The <b>thread:</b> prefix can be used with the thread ID values that
85 are generated internally by notmuch (and do not appear in email
86 messages). These thread ID values can be seen in the first col‐
87 umn of output from <b>notmuch</b> <b>search</b>
89 <b>path:<directory-path></b> <b>or</b> <b>path:<directory-path>/**</b> <b>or</b> <b>path:/<regex>/</b>
90 The <b>path:</b> prefix searches for email messages that are in partic‐
91 ular directories within the mail store. The directory must be
92 specified relative to the top-level maildir (and without the
93 leading slash). By default, <b>path:</b> matches messages in the speci‐
94 fied directory only. The "/**" suffix can be used to match mes‐
95 sages in the specified directory and all its subdirectories
96 recursively. <b>path:""</b> matches messages in the root of the mail
97 store and, likewise, <b>path:**</b> matches all messages.
99 <b>path:</b> will find a message if <u>any</u> copy of that message is in the
102 <b>folder:<maildir-folder></b> <b>or</b> <b>folder:/<regex>/</b>
103 The <b>folder:</b> prefix searches for email messages by maildir or MH
104 folder. For MH-style folders, this is equivalent to <b>path:</b>. For
105 maildir, this includes messages in the "new" and "cur" subdirec‐
106 tories. The exact syntax for maildir folders depends on your
107 mail configuration. For maildir++, <b>folder:""</b> matches the inbox
108 folder (which is the root in maildir++), other folder names
109 always start with ".", and nested folders are separated by "."s,
110 such as <b>folder:.classes.topology</b>. For "file system" maildir, the
111 inbox is typically <b>folder:INBOX</b> and nested folders are separated
112 by slashes, such as <b>folder:classes/topology</b>.
114 <b>folder:</b> will find a message if <u>any</u> copy of that message is in
117 <b>date:<since>..<until></b> <b>or</b> <b>date:<date></b>
118 The <b>date:</b> prefix can be used to restrict the results to only
119 messages within a particular time range (based on the Date:
122 See <b>DATE</b> <b>AND</b> <b>TIME</b> <b>SEARCH</b> below for details on the range expres‐
123 sion, and supported syntax for <since> and <until> date and time
126 The time range can also be specified using timestamps with a
129 <initial-timestamp>..<final-timestamp>
131 Each timestamp is a number representing the number of seconds
132 since 1970-01-01 00:00:00 UTC.
134 <b>lastmod:<initial-revision>..<final-revision></b>
135 The <b>lastmod:</b> prefix can be used to restrict the result by the
136 database revision number of when messages were last modified
137 (tags were added/removed or filenames changed). This is usually
138 used in conjunction with the <b>--uuid</b> argument to <b>notmuch</b> <b>search</b>
139 to find messages that have changed since an earlier query.
141 <b>query:<name></b>
142 The <b>query:</b> prefix allows queries to refer to previously saved
143 queries added with <a href='../notmuch-config-1/'>notmuch-config</a>(1). Named queries are only
144 available if notmuch is built with <b>Xapian</b> <b>Field</b> <b>Processors</b> (see
147 <b>property:<key>=<value></b>
148 The <b>property:</b> prefix searches for messages with a particular
149 <key>=<value> property pair. Properties are used internally by
150 notmuch (and extensions) to add metadata to messages. A given
151 key can be present on a given message with several different
152 values. See <a href='../notmuch-properties-7/'>notmuch-properties</a>(7) for more details.
155 <h3> Operators</h3>
157 In addition to individual terms, multiple terms can be combined with
158 Boolean operators (<b>and</b>, <b>or</b>, <b>not</b>, and <b>xor</b>). Each term in the query will
159 be implicitly connected by a logical AND if no explicit operator is
160 provided (except that terms with a common prefix will be implicitly
161 combined with OR). The shorthand '-<term>' can be used for 'not
162 <term>' but unfortunately this does not work at the start of an expres‐
163 sion. Parentheses can also be used to control the combination of the
164 Boolean operators, but will have to be protected from interpretation by
165 the shell, (such as by putting quotation marks around any parenthesized
168 In addition to the standard boolean operators, Xapian provides several
169 operators specific to text searching.
171 notmuch search term1 NEAR term2
173 will return results where term1 is within 10 words of term2. The
174 threshold can be set like this:
176 notmuch search term1 NEAR/2 term2
180 notmuch search term1 ADJ term2
182 will return results where term1 is within 10 words of term2, but in the
183 same order as in the query. The threshold can be set the same as with
186 notmuch search term1 ADJ/7 term2
189 <h3> Stemming</h3>
191 <b>Stemming</b> in notmuch means that these searches
193 notmuch search detailed
194 notmuch search details
195 notmuch search detail
197 will all return identical results, because Xapian first "reduces" the
198 term to the common stem (here 'detail') and then performs the search.
200 There are two ways to turn this off: a search for a capitalized word
201 will be performed unstemmed, so that one can search for "John" and not
202 get results for "Johnson"; phrase searches are also unstemmed (see
203 below for details). Stemming is currently only supported for English.
204 Searches for words in other languages will be performed unstemmed.
207 <h3> Wildcards</h3>
209 It is possible to use a trailing '*' as a wildcard. A search for
210 'wildc*' will match 'wildcard', 'wildcat', etc.
213 <h3> Boolean and Probabilistic Prefixes</h3>
215 Xapian (and hence notmuch) prefixes are either <b>boolean</b>, supporting
216 exact matches like "<u>tag:inbox</u>" or <b>probabilistic</b>, supporting a more
217 flexible <b>term</b> based searching. Certain <b>special</b> prefixes are processed
218 by notmuch in a way not strictly fitting either of Xapian's built in
219 styles. The prefixes currently supported by notmuch are as follows.
222 <b>tag:</b>, <b>id:</b>, <b>thread:</b>, <b>folder:</b>, <b>path:</b>, <b>property:</b>
225 <b>to:</b>, <b>attachment:</b>, <b>mimetype:</b>
228 <b>from:</b>, <b>query:</b>, <b>subject:</b>
231 <h3> Terms and phrases</h3>
233 In general Xapian distinguishes between lists of terms and <b>phrases</b>.
234 Phrases are indicated by double quotes (but beware you probably need to
235 protect those from your shell) and insist that those unstemmed words
236 occur in that order. One useful, but initially surprising feature is
237 that the following are equivalent ways to write the same phrase.
239 · "a list of words"
247 Both parenthesised lists of terms and quoted phrases are ok with proba‐
248 bilistic prefixes such as <b>to:</b>, <b>from:</b>, and <b>subject:</b>. In particular
254 subject:pizza and subject:free
256 Both of these will match a subject "Free Delicious Pizza" while
258 subject:"pizza free"
263 <h2>DATE AND TIME SEARCH</h2>
265 notmuch understands a variety of standard and natural ways of express‐
266 ing dates and times, both in absolute terms ("2012-10-24") and in rela‐
267 tive terms ("yesterday"). Any number of relative terms can be combined
268 ("1 hour 25 minutes") and an absolute date/time can be combined with
269 relative terms to further adjust it. A non-exhaustive description of
270 the syntax supported for absolute and relative terms is given below.
273 <h3> The range expression</h3>
275 date:<since>..<until>
277 The above expression restricts the results to only messages from
278 <since> to <until>, based on the Date: header.
280 <since> and <until> can describe imprecise times, such as "yesterday".
281 In this case, <since> is taken as the earliest time it could describe
282 (the beginning of yesterday) and <until> is taken as the latest time it
283 could describe (the end of yesterday). Similarly, date:january..febru‐
284 ary matches from the beginning of January to the end of February.
286 date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The
287 expansion takes place before interpretation, and thus, for example,
288 date:monday..! matches from the beginning of Monday until the end of
289 Monday. With <b>Xapian</b> <b>Field</b> <b>Processor</b> support (see below), non-range
290 date queries such as date:yesterday will work, but otherwise will give
291 unexpected results; if in doubt use date:yesterday..!
293 Currently, we do not support spaces in range expressions. You can
294 replace the spaces with '_', or (in most cases) '-', or (in some cases)
295 leave the spaces out altogether. Examples in this man page use spaces
298 Open-ended ranges are supported (since Xapian 1.2.1), i.e. it's possi‐
299 ble to specify date:..<until> or date:<since>.. to not limit the start
300 or end time, respectively. Pre-1.2.1 Xapian does not report an error on
301 open ended ranges, but it does not work as expected either.
304 <h3> Relative date and time</h3>
306 [N|number] (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
309 All refer to past, can be repeated and will be accumulated.
311 Units can be abbreviated to any length, with the otherwise ambiguous
312 single m being m for minutes and M for months.
314 Number can also be written out one, two, ..., ten, dozen, hundred.
315 Additionally, the unit may be preceded by "last" or "this" (e.g., "last
316 week" or "this month").
318 When combined with absolute date and time, the relative date and time
319 specification will be relative from the specified absolute date and
322 Examples: 5M2d, two weeks
325 <h3> Supported absolute time formats</h3>
327 · H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
329 · H[H] (am|a.m.|pm|p.m.)
339 · Examples: 17:05, 5pm
342 <h3> Supported absolute date formats</h3>
356 · D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
358 · Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
362 Month names can be abbreviated at three or more characters.
364 Weekday names can be abbreviated at three or more characters.
366 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
369 <h3> Time zones</h3>
375 Some time zone codes, e.g. UTC, EET.
378 <h2>XAPIAN FIELD PROCESSORS</h2>
380 Certain optional features of the notmuch query processor rely on the
381 presence of the Xapian field processor API. You can determine if your
382 notmuch was built against a sufficiently recent version of Xapian by
385 % notmuch config get built_with.field_processor
387 Currently the following features require field processor support:
389 · non-range date queries, e.g. "date:today"
391 · named queries e.g. "query:my_special_query"
393 · regular expression searches, e.g. "subject:/^\[SPAM\]/"
398 <a href='../notmuch-1/'>notmuch</a>(1), <a href='../notmuch-config-1/'>notmuch-config</a>(1), <a href='../notmuch-count-1/'>notmuch-count</a>(1), <a href='../notmuch-dump-1/'>notmuch-dump</a>(1), <a href='../notmuch-hooks-5/'>not‐</a>
399 <a href='../notmuch-hooks-5/'>much-hooks</a>(5), <a href='../notmuch-insert-1/'>notmuch-insert</a>(1), <a href='../notmuch-new-1/'>notmuch-new</a>(1), <a href='../notmuch-reindex-1/'>notmuch-reindex</a>(1),
400 <b>notmuch-properties</b>(1), <b>*notmuch-reply</b>(1), <a href='../notmuch-restore-1/'>notmuch-restore</a>(1), <a href='../notmuch-search-1/'>not‐</a>
401 <a href='../notmuch-search-1/'>much-search</a>(1), <b>*notmuch-show</b>(1), <a href='../notmuch-tag-1/'>notmuch-tag</a>(1)
406 Carl Worth and many others
411 2009-2018, Carl Worth and many others