1NOTMUCH-SEARCH-TERMS(7)             notmuch            NOTMUCH-SEARCH-TERMS(7)
2
3
4

NAME

6       notmuch-search-terms - syntax for notmuch queries
7

SYNOPSIS

9       notmuch count [option ...] <search-term> ...
10
11       notmuch dump [--gzip] [--format=(batch-tag|sup)] [--output=<file>] [--]
12       [<search-term> ...]
13
14       notmuch reindex [option ...] <search-term> ...
15
16       notmuch search [option ...] <search-term> ...
17
18       notmuch show [option ...] <search-term> ...
19
20       notmuch tag +<tag> ... -<tag> [--] <search-term> ...
21

DESCRIPTION

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 recipi‐
28       ent headers.
29
30       As  a  special case, a search string consisting of exactly a single as‐
31       terisk ("*") will match all messages.
32
33   Search prefixes
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).
37
38       Some of the prefixes with <regex> forms can be also  used  to  restrict
39       the  results  to  those  whose  value matches a regular expression (see
40       regex(7)) delimited with //, for example:
41
42          notmuch search 'from:"/bob@.*[.]example[.]com/"'
43
44       body:<word-or-quoted-phrase>
45              Match terms in the body of messages.
46
47       from:<name-or-address> or from:/<regex>/
48              The from: prefix is used to match the name  or  address  of  the
49              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,  imme‐
59              diately following subject:.
60
61       attachment:<word>
62              The  attachment: prefix can be used to search for specific file‐
63              names (or extensions) of attachments to email messages.
64
65       mimetype:<word>
66              The mimetype: prefix will be used to match text  from  the  con‐
67              tent-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  unread  by
72              default  for new messages added by notmuch-new(1) as well as any
73              other tag values added manually with notmuch-tag(1).
74
75       id:<message-id> or mid:<message-id> or mid:/<regex>/
76              For id: and mid:, message ID values are the literal contents  of
77              the  Message-ID:  header of email messages, but without the '<',
78              '>' 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  col‐
84              umn of output from notmuch-search(1)
85
86       thread:{<notmuch query>}
87              Threads may be searched for indirectly by providing an arbitrary
88              notmuch query in {}. For example, the following returns  threads
89              containing  a  message from mallory and one (not necessarily the
90              same message) with Subject containing the word "crypto".
91
92                 % notmuch search 'thread:"{from:mallory}" and thread:"{subject:crypto}"'
93
94              The performance of such queries can vary wildly.  To  understand
95              this, the user should think of the query thread:{<something>} as
96              expanding to all of the thread IDs which match <something>; not‐
97              much then performs a second search using the expanded query.
98
99       path:<directory-path> or path:<directory-path>/** or path:/<regex>/
100              The path: prefix searches for email messages that are in partic‐
101              ular directories within the mail store. The  directory  must  be
102              specified  relative  to  the  top-level maildir (and without the
103              leading slash). By default, path: matches messages in the speci‐
104              fied  directory only. The "/**" suffix can be used to match mes‐
105              sages in the specified directory and all its subdirectories  re‐
106              cursively.  path:""  matches  messages  in  the root of the mail
107              store and, likewise, path:** matches all messages.
108
109              path: will find a message if any copy of that message is in  the
110              specific directory.
111
112       folder:<maildir-folder> or folder:/<regex>/
113              The  folder: prefix searches for email messages by maildir or MH
114              folder. For MH-style folders, this is equivalent to  path:.  For
115              maildir, this includes messages in the "new" and "cur" subdirec‐
116              tories. The exact syntax for maildir  folders  depends  on  your
117              mail  configuration.  For maildir++, folder:"" matches the inbox
118              folder (which is the root in maildir++), other folder names  al‐
119              ways  start  with ".", and nested folders are separated by "."s,
120              such as folder:.classes.topology. For "file system" maildir, the
121              inbox is typically folder:INBOX and nested folders are separated
122              by slashes, such as folder:classes/topology.
123
124              folder: will find a message if any copy of that  message  is  in
125              the specific folder.
126
127       date:<since>..<until> or date:<date>
128              The  date:  prefix  can  be used to restrict the results to only
129              messages within a particular time  range  (based  on  the  Date:
130              header).
131
132              See  DATE AND TIME SEARCH below for details on the range expres‐
133              sion, and supported syntax for <since> and <until> date and time
134              expressions.
135
136              The  time  range  can also be specified using timestamps without
137              including the date prefix using a syntax of:
138
139              <initial-timestamp>..<final-timestamp>
140
141              Each timestamp is a number representing the  number  of  seconds
142              since  1970-01-01 00:00:00 UTC. Specifying a time range this way
143              is considered legacy and predates the date prefix.
144
145       lastmod:<initial-revision>..<final-revision>
146              The lastmod: prefix can be used to restrict the  result  by  the
147              database  revision  number  of  when messages were last modified
148              (tags were added/removed or filenames changed). This is  usually
149              used   in   conjunction   with   the  --uuid  argument  to  not‐
150              much-search(1) to find messages that have changed since an  ear‐
151              lier query.
152
153       query:<name>
154              The  query:  prefix  allows queries to refer to previously saved
155              queries added with notmuch-config(1).
156
157       property:<key>=<value>
158              The property: prefix searches for  messages  with  a  particular
159              <key>=<value>  property  pair. Properties are used internally by
160              notmuch (and extensions) to add metadata to  messages.  A  given
161              key  can  be  present  on a given message with several different
162              values.  See notmuch-properties(7) for more details.
163
164       sexp:<subquery>
165              The sexp: prefix allows subqueries in the format  documented  in
166              notmuch-sexp-queries(7).  Note that subqueries containing spaces
167              must be quoted, and any embedded double quotes must  be  escaped
168              (see Quoting).
169
170       User defined prefixes are also supported, see notmuch-config(1) for de‐
171       tails.
172
173   Operators
174       In addition to individual terms, multiple terms can  be  combined  with
175       Boolean  operators (and, or, not, and xor). Each term in the query will
176       be implicitly connected by a logical AND if  no  explicit  operator  is
177       provided  (except  that  terms  with a common prefix will be implicitly
178       combined with OR).  The  shorthand  '-<term>'  can  be  used  for  'not
179       <term>' but unfortunately this does not work at the start of an expres‐
180       sion.  Parentheses can also be used to control the combination  of  the
181       Boolean operators, but will have to be protected from interpretation by
182       the shell, (such as by putting quotation marks around any parenthesized
183       expression).
184
185       In  addition to the standard boolean operators, Xapian provides several
186       operators specific to text searching.
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          notmuch search term1 NEAR/2 term2
194
195       The search
196
197          notmuch search term1 ADJ term2
198
199       will return results where term1 is within 10 words of term2, but in the
200       same order as in the query. The threshold can be set the same  as  with
201       NEAR:
202
203          notmuch search term1 ADJ/7 term2
204
205   Stemming
206       Stemming in notmuch means that these searches
207
208          notmuch search detailed
209          notmuch search details
210          notmuch search detail
211
212       will  all  return identical results, because Xapian first "reduces" the
213       term to the common stem (here 'detail') and then performs the search.
214
215       There are two ways to turn this off: a search for  a  capitalized  word
216       will  be performed unstemmed, so that one can search for "John" and not
217       get results for "Johnson"; phrase searches are also unstemmed (see  be‐
218       low  for  details).   Stemming is currently only supported for English.
219       Searches for words in other languages will be performed unstemmed.
220
221   Wildcards
222       It is possible to use a trailing  '*'  as  a  wildcard.  A  search  for
223       'wildc*' will match 'wildcard', 'wildcat', etc.
224
225   Boolean and Probabilistic Prefixes
226       Xapian  (and hence notmuch) prefixes are either boolean, supporting ex‐
227       act matches like "tag:inbox" or probabilistic, supporting a more flexi‐
228       ble  term  based  searching.  Certain special prefixes are processed by
229       notmuch in a way not strictly  fitting  either  of  Xapian's  built  in
230       styles. The prefixes currently supported by notmuch are as follows.
231
232       Boolean
233              tag:, id:, thread:, folder:, path:, property:
234
235       Probabilistic
236              body:, to:, attachment:, mimetype:
237
238       Special
239              from:, query:, subject:, sexp:
240
241   Terms and phrases
242       In  general  Xapian  distinguishes  between lists of terms and phrases.
243       Phrases are indicated by double quotes (but beware you probably need to
244       protect  those  from  your shell) and insist that those unstemmed words
245       occur in that order. One useful, but initially  surprising  feature  is
246       that the following are equivalent ways to write the same phrase.
247
248       • "a list of words"
249
250       • a-list-of-words
251
252       • a/list/of/words
253
254       • a.list.of.words
255
256       Both parenthesised lists of terms and quoted phrases are ok with proba‐
257       bilistic prefixes such as to:, from:, and subject:.  For prefixes  sup‐
258       porting regex search, the parenthesised list should be quoted.  In par‐
259       ticular
260
261          subject:"(pizza free)"
262
263       is equivalent to
264
265          subject:pizza and subject:free
266
267       Both of these will match a subject "Free Delicious Pizza" while
268
269          subject:"pizza free"
270
271       will not.
272
273   Quoting
274       Double quotes are also used by the  notmuch  query  parser  to  protect
275       boolean  terms, regular expressions, or subqueries containing spaces or
276       other special characters, e.g.
277
278          tag:"a tag"
279
280          folder:"/^.*/(Junk|Spam)$/"
281
282          thread:"{from:mallory and date:2009}"
283
284       As with phrases, you need to protect the double quotes from  the  shell
285       e.g.
286
287          % notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
288          % notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
289
290       Double quotes within query strings need to be doubled to escape them.
291
292          % notmuch search 'tag:"""quoted tag"""'
293          % notmuch search 'sexp:"(or ""wizard"" ""php"")"'
294
296       notmuch  understands a variety of standard and natural ways of express‐
297       ing dates and times, both in absolute terms ("2012-10-24") and in rela‐
298       tive  terms ("yesterday"). Any number of relative terms can be combined
299       ("1 hour 25 minutes") and an absolute date/time can  be  combined  with
300       relative  terms  to  further adjust it. A non-exhaustive description of
301       the syntax supported for absolute and relative terms is given below.
302
303   The range expression
304       date:<since>..<until>
305
306       The above expression  restricts  the  results  to  only  messages  from
307       <since> to <until>, based on the Date: header.
308
309       <since>  and <until> can describe imprecise times, such as "yesterday".
310       In this case, <since> is taken as the earliest time it  could  describe
311       (the beginning of yesterday) and <until> is taken as the latest time it
312       could describe (the end of yesterday). Similarly,  date:january..febru‐
313       ary matches from the beginning of January to the end of February.
314
315       If  specifying  a  time  range using timestamps in conjunction with the
316       date prefix, each timestamp must be preceded by @ (ASCII  hex  40).  As
317       above,  each  timestamp  is a number representing the number of seconds
318       since 1970-01-01 00:00:00 UTC. For example:
319          date:@<initial-timestamp>..@<final-timestamp>
320
321       Currently, spaces in range expressions are not supported. You  can  re‐
322       place  the  spaces with '_', or (in most cases) '-', or (in some cases)
323       leave the spaces out altogether. Examples in this man page  use  spaces
324       for clarity.
325
326       Open-ended   ranges  are  supported.  I.e.  it's  possible  to  specify
327       date:..<until> or date:<since>.. to not limit the start  or  end  time,
328       respectively.
329
330   Single expression
331       date:<expr> works as a shorthand for date:<expr>..<expr>.  For example,
332       date:monday matches from the beginning of Monday until the end of  Mon‐
333       day.
334
335   Relative date and time
336       [N|number]         (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
337       onds|secs) [...]
338
339       All refer to past, can be repeated and will be accumulated.
340
341       Units can be abbreviated to any length, with  the  otherwise  ambiguous
342       single m being m for minutes and M for months.
343
344       Number can also be written out one, two, ..., ten, dozen, hundred.  Ad‐
345       ditionally, the unit may be preceded by "last" or "this"  (e.g.,  "last
346       week" or "this month").
347
348       When  combined  with absolute date and time, the relative date and time
349       specification will be relative from the  specified  absolute  date  and
350       time.
351
352       Examples: 5M2d, two weeks
353
354   Supported absolute time formats
355       • H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
356
357       • H[H] (am|a.m.|pm|p.m.)
358
359       • HHMMSS
360
361       • now
362
363       • noon
364
365       • midnight
366
367       • Examples: 17:05, 5pm
368
369   Supported absolute date formats
370       • YYYY-MM[-DD]
371
372       • DD-MM[-[YY]YY]
373
374       • MM-YYYY
375
376       • M[M]/D[D][/[YY]YY]
377
378       • M[M]/YYYY
379
380       • D[D].M[M][.[YY]YY]
381
382       • D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
383
384       • Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
385
386       • Wee[kday]
387
388       Month names can be abbreviated at three or more characters.
389
390       Weekday names can be abbreviated at three or more characters.
391
392       Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
393
394   Time zones
395       • (+|-)HH:MM
396
397       • (+|-)HH[MM]
398
399       Some time zone codes, e.g. UTC, EET.
400

SEE ALSO

402       notmuch(1),  notmuch-config(1), notmuch-count(1), notmuch-dump(1), not‐
403       much-hooks(5),   notmuch-insert(1),   notmuch-new(1),   notmuch-proper‐
404       ties(7), notmuch-reindex(1), notmuch-reply(1), notmuch-restore(1), not‐
405       much-search(1), notmuch-show(1), notmuch-tag(1)
406

AUTHOR

408       Carl Worth and many others
409
411       2009-2022, Carl Worth and many others
412
413
414
415
4160.36                             Jun 25, 2022          NOTMUCH-SEARCH-TERMS(7)
Impressum