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 as well as any
73              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 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
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).  Negative  revi‐
149              sions are interpreted relative to the most recent database revi‐
150              sion (see count --lastmod). This is usually used in  conjunction
151              with the --uuid argument to notmuch-search to find messages that
152              have changed since an earlier query.
153
154       query:<name>
155              The query: prefix allows queries to refer  to  previously  saved
156              queries added with notmuch-config.
157
158       property:<key>=<value>
159              The  property:  prefix  searches  for messages with a particular
160              <key>=<value> property pair. Properties are used  internally  by
161              notmuch  (and  extensions)  to add metadata to messages. A given
162              key can be present on a given  message  with  several  different
163              values.  See notmuch-properties for more details.
164
165       sexp:<subquery>
166              The  sexp:  prefix allows subqueries in the format documented in
167              notmuch-sexp-queries. Note  that  subqueries  containing  spaces
168              must  be  quoted, and any embedded double quotes must be escaped
169              (see Quoting).
170
171       User defined prefixes are also supported, see  notmuch-config  for  de‐
172       tails.
173
174   Operators
175       In  addition  to  individual terms, multiple terms can be combined with
176       Boolean operators (and, or, not, and xor). Each term in the query  will
177       be  implicitly  connected  by  a logical AND if no explicit operator is
178       provided (except that terms with a common  prefix  will  be  implicitly
179       combined  with  OR).   The  shorthand  '-<term>'  can  be used for 'not
180       <term>' but unfortunately this does not work at the start of an expres‐
181       sion.   Parentheses  can also be used to control the combination of the
182       Boolean operators, but will have to be protected from interpretation by
183       the shell, (such as by putting quotation marks around any parenthesized
184       expression).
185
186       In addition to the standard boolean operators, Xapian provides  several
187       operators specific to text searching.
188
189          notmuch search term1 NEAR term2
190
191       will  return  results  where  term1  is  within  10 words of term2. The
192       threshold can be set like this:
193
194          notmuch search term1 NEAR/2 term2
195
196       The search
197
198          notmuch search term1 ADJ term2
199
200       will return results where term1 is within 10 words of term2, but in the
201       same  order  as in the query. The threshold can be set the same as with
202       NEAR:
203
204          notmuch search term1 ADJ/7 term2
205
206   Stemming
207       Stemming in notmuch means that these searches
208
209          notmuch search detailed
210          notmuch search details
211          notmuch search detail
212
213       will all return identical results, because Xapian first  "reduces"  the
214       term to the common stem (here 'detail') and then performs the search.
215
216       There  are  two  ways to turn this off: a search for a capitalized word
217       will be performed unstemmed, so that one can search for "John" and  not
218       get  results for "Johnson"; phrase searches are also unstemmed (see be‐
219       low for details).  Stemming is currently only  supported  for  English.
220       Searches for words in other languages will be performed unstemmed.
221
222   Wildcards
223       It  is  possible  to  use  a  trailing  '*' as a wildcard. A search for
224       'wildc*' will match 'wildcard', 'wildcat', etc.
225
226   Boolean and Probabilistic Prefixes
227       Xapian (and hence notmuch) prefixes are either boolean, supporting  ex‐
228       act matches like "tag:inbox" or probabilistic, supporting a more flexi‐
229       ble term based searching. Certain special  prefixes  are  processed  by
230       notmuch  in  a  way  not  strictly  fitting either of Xapian's built in
231       styles. The prefixes currently supported by notmuch are as follows.
232
233       Boolean
234              tag:, id:, thread:, folder:, path:, property:
235
236       Probabilistic
237              body:, to:, attachment:, mimetype:
238
239       Special
240              from:, query:, subject:, sexp:
241
242   Terms and phrases
243       In general Xapian distinguishes between lists  of  terms  and  phrases.
244       Phrases are indicated by double quotes (but beware you probably need to
245       protect those from your shell) and insist that  those  unstemmed  words
246       occur  in  that  order. One useful, but initially surprising feature is
247       that the following are equivalent ways to write the same phrase.
248
249       • "a list of words"
250
251       • a-list-of-words
252
253       • a/list/of/words
254
255       • a.list.of.words
256
257       Both parenthesised lists of terms and quoted phrases are ok with proba‐
258       bilistic  prefixes such as to:, from:, and subject:.  For prefixes sup‐
259       porting regex search, the parenthesised list should be quoted.  In par‐
260       ticular
261
262          subject:"(pizza free)"
263
264       is equivalent to
265
266          subject:pizza and subject:free
267
268       Both of these will match a subject "Free Delicious Pizza" while
269
270          subject:"pizza free"
271
272       will not.
273
274   Quoting
275       Double  quotes  are  also  used  by the notmuch query parser to protect
276       boolean terms, regular expressions, or subqueries containing spaces  or
277       other special characters, e.g.
278
279          tag:"a tag"
280
281          folder:"/^.*/(Junk|Spam)$/"
282
283          thread:"{from:mallory and date:2009}"
284
285       As  with  phrases, you need to protect the double quotes from the shell
286       e.g.
287
288          % notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
289          % notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
290
291       Double quotes within query strings need to be doubled to escape them.
292
293          % notmuch search 'tag:"""quoted tag"""'
294          % notmuch search 'sexp:"(or ""wizard"" ""php"")"'
295
297       notmuch understands a variety of standard and natural ways of  express‐
298       ing dates and times, both in absolute terms ("2012-10-24") and in rela‐
299       tive terms ("yesterday"). Any number of relative terms can be  combined
300       ("1  hour  25  minutes") and an absolute date/time can be combined with
301       relative terms to further adjust it. A  non-exhaustive  description  of
302       the syntax supported for absolute and relative terms is given below.
303
304   The range expression
305       date:<since>..<until>
306
307       The  above  expression  restricts  the  results  to  only messages from
308       <since> to <until>, based on the Date: header.
309
310       <since> and <until> can describe imprecise times, such as  "yesterday".
311       In  this  case, <since> is taken as the earliest time it could describe
312       (the beginning of yesterday) and <until> is taken as the latest time it
313       could  describe (the end of yesterday). Similarly, date:january..febru‐
314       ary matches from the beginning of January to the end of February.
315
316       If specifying a time range using timestamps  in  conjunction  with  the
317       date  prefix,  each  timestamp must be preceded by @ (ASCII hex 40). As
318       above, each timestamp is a number representing the  number  of  seconds
319       since 1970-01-01 00:00:00 UTC. For example:
320          date:@<initial-timestamp>..@<final-timestamp>
321
322       Currently,  spaces  in range expressions are not supported. You can re‐
323       place the spaces with '_', or (in most cases) '-', or (in  some  cases)
324       leave  the  spaces out altogether. Examples in this man page use spaces
325       for clarity.
326
327       Open-ended  ranges  are  supported.  I.e.  it's  possible  to   specify
328       date:..<until>  or  date:<since>..  to not limit the start or end time,
329       respectively.
330
331   Single expression
332       date:<expr> works as a shorthand for date:<expr>..<expr>.  For example,
333       date:monday  matches from the beginning of Monday until the end of Mon‐
334       day.
335
336   Relative date and time
337       [N|number]         (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
338       onds|secs) [...]
339
340       All refer to past, can be repeated and will be accumulated.
341
342       Units  can  be  abbreviated to any length, with the otherwise ambiguous
343       single m being m for minutes and M for months.
344
345       Number can also be written out one, two, ..., ten, dozen, hundred.  Ad‐
346       ditionally,  the  unit may be preceded by "last" or "this" (e.g., "last
347       week" or "this month").
348
349       When combined with absolute date and time, the relative date  and  time
350       specification  will  be  relative  from the specified absolute date and
351       time.
352
353       Examples: 5M2d, two weeks
354
355   Supported absolute time formats
356       • H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
357
358       • H[H] (am|a.m.|pm|p.m.)
359
360       • HHMMSS
361
362       • now
363
364       • noon
365
366       • midnight
367
368       • Examples: 17:05, 5pm
369
370   Supported absolute date formats
371       • YYYY-MM[-DD]
372
373       • DD-MM[-[YY]YY]
374
375       • MM-YYYY
376
377       • M[M]/D[D][/[YY]YY]
378
379       • M[M]/YYYY
380
381       • D[D].M[M][.[YY]YY]
382
383       • D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
384
385       • Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
386
387       • Wee[kday]
388
389       Month names can be abbreviated at three or more characters.
390
391       Weekday names can be abbreviated at three or more characters.
392
393       Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
394
395   Time zones
396       • (+|-)HH:MM
397
398       • (+|-)HH[MM]
399
400       Some time zone codes, e.g. UTC, EET.
401

SEE ALSO

403       notmuch, notmuch-config,  notmuch-count,  notmuch-dump,  notmuch-hooks,
404       notmuch-insert,   notmuch-new,   notmuch-properties,   notmuch-reindex,
405       notmuch-reply,    notmuch-restore,    notmuch-search,     notmuch-show,
406       notmuch-tag
407

AUTHOR

409       Carl Worth and many others
410
412       2009-2023, Carl Worth and many others
413
414
415
416
4170.38                             Sep 12, 2023          NOTMUCH-SEARCH-TERMS(7)
Impressum