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