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>search</b> [option ...] <<u>search-term</u>> ...
17 <b>notmuch</b> <b>show</b> [option ...] <<u>search-term</u>> ...
19 <b>notmuch</b> <b>tag</b> +<<u>tag</u>> ... -<<u>tag</u>> [--] <<u>search-term</u>> ...
24 Several notmuch commands accept a common syntax for search terms.
26 The search terms can consist of free-form text (and quoted phrases)
27 which will match all messages that contain all of the given
28 terms/phrases in the body, the subject, or any of the sender or recipi‐
31 As a special case, a search string consisting of exactly a single
32 asterisk ("*") will match all messages.
34 In addition to free text, the following prefixes can be used to force
35 terms to match against specific portions of an email, (where <brackets>
36 indicate user-supplied values):
38 · from:<name-or-address>
40 · to:<name-or-address>
42 · subject:<word-or-quoted-phrase>
44 · attachment:<word>
46 · mimetype:<word>
48 · tag:<tag> (or is:<tag>)
50 · id:<message-id>
52 · thread:<thread-id>
54 · folder:<maildir-folder>
56 · path:<directory-path> or path:<directory-path>/**
58 · date:<since>..<until>
60 · lastmod:<initial-revision>..<final-revision>
64 · property:<key>=<value>
66 The <b>from:</b> prefix is used to match the name or address of the sender of
69 The <b>to:</b> prefix is used to match the names or addresses of any recipient
70 of an email message, (whether To, Cc, or Bcc).
72 Any term prefixed with <b>subject:</b> will match only text from the subject
73 of an email. Searching for a phrase in the subject is supported by
74 including quotation marks around the phrase, immediately following <b>sub-</b>
77 The <b>attachment:</b> prefix can be used to search for specific filenames (or
78 extensions) of attachments to email messages.
80 The <b>mimetype:</b> prefix will be used to match text from the content-types
81 of MIME parts within email messages (as specified by the sender).
83 For <b>tag:</b> and <b>is:</b> valid tag values include <b>inbox</b> and <b>unread</b> by default
84 for new messages added by <b>notmuch</b> <b>new</b> as well as any other tag values
85 added manually with <b>notmuch</b> <b>tag</b>.
87 For <b>id:</b>, message ID values are the literal contents of the Message-ID:
88 header of email messages, but without the '<', '>' delimiters.
90 The <b>thread:</b> prefix can be used with the thread ID values that are gen‐
91 erated internally by notmuch (and do not appear in email messages).
92 These thread ID values can be seen in the first column of output from
93 <b>notmuch</b> <b>search</b>
95 The <b>path:</b> prefix searches for email messages that are in particular
96 directories within the mail store. The directory must be specified rel‐
97 ative to the top-level maildir (and without the leading slash). By
98 default, <b>path:</b> matches messages in the specified directory only. The
99 "/**" suffix can be used to match messages in the specified directory
100 and all its subdirectories recursively. <b>path:""</b> matches messages in
101 the root of the mail store and, likewise, <b>path:**</b> matches all messages.
103 The <b>folder:</b> prefix searches for email messages by maildir or MH folder.
104 For MH-style folders, this is equivalent to <b>path:</b>. For maildir, this
105 includes messages in the "new" and "cur" subdirectories. The exact syn‐
106 tax for maildir folders depends on your mail configuration. For
107 maildir++, <b>folder:""</b> matches the inbox folder (which is the root in
108 maildir++), other folder names always start with ".", and nested fold‐
109 ers are separated by "."s, such as <b>folder:.classes.topology</b>. For "file
110 system" maildir, the inbox is typically <b>folder:INBOX</b> and nested folders
111 are separated by slashes, such as <b>folder:classes/topology</b>.
113 Both <b>path:</b> and <b>folder:</b> will find a message if <u>any</u> copy of that message
114 is in the specific directory/folder.
116 The <b>date:</b> prefix can be used to restrict the results to only messages
117 within a particular time range (based on the Date: header) with a range
120 date:<since>..<until>
122 See <b>DATE</b> <b>AND</b> <b>TIME</b> <b>SEARCH</b> below for details on the range expression, and
123 supported syntax for <since> and <until> date and time expressions.
125 The time range can also be specified using timestamps with a syntax of:
127 <initial-timestamp>..<final-timestamp>
129 Each timestamp is a number representing the number of seconds since
130 1970-01-01 00:00:00 UTC.
132 The <b>lastmod:</b> prefix can be used to restrict the result by the database
133 revision number of when messages were last modified (tags were
134 added/removed or filenames changed). This is usually used in conjunc‐
135 tion with the <b>--uuid</b> argument to <b>notmuch</b> <b>search</b> to find messages that
136 have changed since an earlier query.
138 The <b>query:</b> prefix allows queries to refer to previously saved queries
139 added with <a href='../notmuch-config-1/'>notmuch-config</a>(1). Named queries are only available if not‐
140 much is built with <b>Xapian</b> <b>Field</b> <b>Processors</b> (see below).
142 The <b>property:</b> prefix searches for messages with a particular
143 <key>=<value> property pair. Properties are used internally by notmuch
144 (and extensions) to add metadata to messages. A given key can be
145 present on a given message with several different values.
148 <h3> Operators</h3>
150 In addition to individual terms, multiple terms can be combined with
151 Boolean operators (<b>and</b>, <b>or</b>, <b>not</b>, and <b>xor</b>). Each term in the query will
152 be implicitly connected by a logical AND if no explicit operator is
153 provided (except that terms with a common prefix will be implicitly
154 combined with OR). The shorthand '-<term>' can be used for 'not
155 <term>' but unfortunately this does not work at the start of an expres‐
156 sion. Parentheses can also be used to control the combination of the
157 Boolean operators, but will have to be protected from interpretation by
158 the shell, (such as by putting quotation marks around any parenthesized
161 In addition to the standard boolean operators, Xapian provides several
162 operators specific to text searching.
164 notmuch search term1 NEAR term2
166 will return results where term1 is within 10 words of term2. The
167 threshold can be set like this:
169 notmuch search term1 NEAR/2 term2
173 notmuch search term1 ADJ term2
175 will return results where term1 is within 10 words of term2, but in the
176 same order as in the query. The threshold can be set the same as with
179 notmuch search term1 ADJ/7 term2
182 <h3> Stemming</h3>
184 <b>Stemming</b> in notmuch means that these searches
186 notmuch search detailed
187 notmuch search details
188 notmuch search detail
190 will all return identical results, because Xapian first "reduces" the
191 term to the common stem (here 'detail') and then performs the search.
193 There are two ways to turn this off: a search for a capitalized word
194 will be performed unstemmed, so that one can search for "John" and not
195 get results for "Johnson"; phrase searches are also unstemmed (see
196 below for details). Stemming is currently only supported for English.
197 Searches for words in other languages will be performed unstemmed.
200 <h3> Wildcards</h3>
202 It is possible to use a trailing '*' as a wildcard. A search for
203 'wildc*' will match 'wildcard', 'wildcat', etc.
206 <h3> Boolean and Probabilistic Prefixes</h3>
208 Xapian (and hence notmuch) prefixes are either <b>boolean</b>, supporting
209 exact matches like "<u>tag:inbox</u>" or <b>probabilistic</b>, supporting a more
210 flexible <b>term</b> based searching. The prefixes currently supported by not‐
214 <b>tag:</b>, <b>id:</b>, <b>thread:</b>, <b>folder:</b>, <b>path:</b>, <b>property:</b>
217 <b>from:</b>, <b>to:</b>, <b>subject:</b>, <b>attachment:</b>, <b>mimetype:</b>
220 <h3> Terms and phrases</h3>
222 In general Xapian distinguishes between lists of terms and <b>phrases</b>.
223 Phrases are indicated by double quotes (but beware you probably need to
224 protect those from your shell) and insist that those unstemmed words
225 occur in that order. One useful, but initially surprising feature is
226 that the following are equivalant ways to write the same phrase.
228 · "a list of words"
236 Both parenthesised lists of terms and quoted phrases are ok with proba‐
237 bilisitic prefixes such as <b>to:</b>, <b>from:</b>, and <b>subject:</b>. In particular
243 subject:pizza and subject:free
245 Both of these will match a subject "Free Delicious Pizza" while
247 subject:"pizza free"
252 <h2>DATE AND TIME SEARCH</h2>
254 notmuch understands a variety of standard and natural ways of express‐
255 ing dates and times, both in absolute terms ("2012-10-24") and in rela‐
256 tive terms ("yesterday"). Any number of relative terms can be combined
257 ("1 hour 25 minutes") and an absolute date/time can be combined with
258 relative terms to further adjust it. A non-exhaustive description of
259 the syntax supported for absolute and relative terms is given below.
262 <h3> The range expression</h3>
264 date:<since>..<until>
266 The above expression restricts the results to only messages from
267 <since> to <until>, based on the Date: header.
269 <since> and <until> can describe imprecise times, such as "yesterday".
270 In this case, <since> is taken as the earliest time it could describe
271 (the beginning of yesterday) and <until> is taken as the latest time it
272 could describe (the end of yesterday). Similarly, date:january..febru‐
273 ary matches from the beginning of January to the end of February.
275 date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The
276 expansion takes place before interpretation, and thus, for example,
277 date:monday..! matches from the beginning of Monday until the end of
278 Monday. With <b>Xapian</b> <b>Field</b> <b>Processor</b> support (see below), non-range
279 date queries such as date:yesterday will work, but otherwise will give
280 unexpected results; if in doubt use date:yesterday..!
282 Currently, we do not support spaces in range expressions. You can
283 replace the spaces with '_', or (in most cases) '-', or (in some cases)
284 leave the spaces out altogether. Examples in this man page use spaces
287 Open-ended ranges are supported (since Xapian 1.2.1), i.e. it's possi‐
288 ble to specify date:..<until> or date:<since>.. to not limit the start
289 or end time, respectively. Pre-1.2.1 Xapian does not report an error on
290 open ended ranges, but it does not work as expected either.
293 <h3> Relative date and time</h3>
295 [N|number] (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
298 All refer to past, can be repeated and will be accumulated.
300 Units can be abbreviated to any length, with the otherwise ambiguous
301 single m being m for minutes and M for months.
303 Number can also be written out one, two, ..., ten, dozen, hundred.
304 Additionally, the unit may be preceded by "last" or "this" (e.g., "last
305 week" or "this month").
307 When combined with absolute date and time, the relative date and time
308 specification will be relative from the specified absolute date and
311 Examples: 5M2d, two weeks
314 <h3> Supported absolute time formats</h3>
316 · H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
318 · H[H] (am|a.m.|pm|p.m.)
328 · Examples: 17:05, 5pm
331 <h3> Supported absolute date formats</h3>
345 · D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
347 · Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
351 Month names can be abbreviated at three or more characters.
353 Weekday names can be abbreviated at three or more characters.
355 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
358 <h3> Time zones</h3>
364 Some time zone codes, e.g. UTC, EET.
367 <h2>XAPIAN FIELD PROCESSORS</h2>
369 Certain optional features of the notmuch query processor rely on the
370 presence of the Xapian field processor API. You can determine if your
371 notmuch was built against a sufficiently recent version of Xapian by
374 % notmuch config get built_with.field_processor
376 Currently the following features require field processor support:
378 · non-range date queries, e.g. "date:today"
380 · named queries e.g. "query:my_special_query"
385 <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>
386 <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-reply-1/'>notmuch-reply</a>(1),
387 <a href='../notmuch-restore-1/'>notmuch-restore</a>(1), <a href='../notmuch-search-1/'>notmuch-search</a>(1), <a href='../notmuch-show-1/'>notmuch-show</a>(1), <a href='../notmuch-tag-1/'>notmuch-tag</a>(1)
392 Carl Worth and many others
397 2009-2016, Carl Worth and many others