]> git.cworth.org Git - notmuch-wiki/blob - manpages/notmuch-search-terms-7.mdwn
complete sentence
[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 <a href='../notmuch-new-1/'>notmuch-new</a>(1) as well as any
78               other tag values added manually with <a href='../notmuch-tag-1/'>notmuch-tag</a>(1).
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 <a href='../notmuch-search-1/'>notmuch-search</a>(1)
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  <a href='../notmuch-search-1/'>not‐</a>
155               <a href='../notmuch-search-1/'>much-search</a>(1) to find messages that have changed since an  ear‐
156               lier query.
157
158        <b>query:&lt;name&gt;</b>
159               The  <b>query:</b>  prefix  allows queries to refer to previously saved
160               queries added with <a href='../notmuch-config-1/'>notmuch-config</a>(1).
161
162        <b>property:&lt;key&gt;=&lt;value&gt;</b>
163               The <b>property:</b> prefix searches for  messages  with  a  particular
164               &lt;key&gt;=&lt;value&gt;  property  pair. Properties are used internally by
165               notmuch (and extensions) to add metadata to  messages.  A  given
166               key  can  be  present  on a given message with several different
167               values.  See <a href='../notmuch-properties-7/'>notmuch-properties</a>(7) for more details.
168
169        User defined prefixes are also supported, see <a href='../notmuch-config-1/'>notmuch-config</a>(1) for de‐
170        tails.
171 </pre>
172
173 <h3> &nbsp; Operators</h3>
174 <pre>
175        In  addition  to  individual terms, multiple terms can be combined with
176        Boolean operators (<b>and</b>, <b>or</b>, <b>not</b>, and <b>xor</b>). 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  &apos;-&lt;term&gt;&apos;  can  be used for &apos;not
180        &lt;term&gt;&apos; 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 </pre>
206
207 <h3> &nbsp; Stemming</h3>
208 <pre>
209        <b>Stemming</b> in notmuch means that these searches
210
211           notmuch search detailed
212           notmuch search details
213           notmuch search detail
214
215        will all return identical results, because Xapian first  &quot;reduces&quot;  the
216        term to the common stem (here &apos;detail&apos;) and then performs the search.
217
218        There  are  two  ways to turn this off: a search for a capitalized word
219        will be performed unstemmed, so that one can search for &quot;John&quot; and  not
220        get  results for &quot;Johnson&quot;; phrase searches are also unstemmed (see be‐
221        low for details).  Stemming is currently only  supported  for  English.
222        Searches for words in other languages will be performed unstemmed.
223 </pre>
224
225 <h3> &nbsp; Wildcards</h3>
226 <pre>
227        It  is  possible  to  use  a  trailing  &apos;*&apos; as a wildcard. A search for
228        &apos;wildc*&apos; will match &apos;wildcard&apos;, &apos;wildcat&apos;, etc.
229 </pre>
230
231 <h3> &nbsp; Boolean and Probabilistic Prefixes</h3>
232 <pre>
233        Xapian (and hence notmuch) prefixes are either <b>boolean</b>, supporting  ex‐
234        act matches like &quot;<u>tag:inbox</u>&quot; or <b>probabilistic</b>, supporting a more flexi‐
235        ble <b>term</b> based searching. Certain <b>special</b>  prefixes  are  processed  by
236        notmuch  in  a  way  not  strictly  fitting either of Xapian&apos;s built in
237        styles. The prefixes currently supported by notmuch are as follows.
238
239        <b>Boolean</b>
240               <b>tag:</b>, <b>id:</b>, <b>thread:</b>, <b>folder:</b>, <b>path:</b>, <b>property:</b>
241
242        <b>Probabilistic</b>
243               <b>body:</b>, <b>to:</b>, <b>attachment:</b>, <b>mimetype:</b>
244
245        <b>Special</b>
246               <b>from:</b>, <b>query:</b>, <b>subject:</b>
247 </pre>
248
249 <h3> &nbsp; Terms and phrases</h3>
250 <pre>
251        In general Xapian distinguishes between lists  of  terms  and  <b>phrases</b>.
252        Phrases are indicated by double quotes (but beware you probably need to
253        protect those from your shell) and insist that  those  unstemmed  words
254        occur  in  that  order. One useful, but initially surprising feature is
255        that the following are equivalent ways to write the same phrase.
256
257        • &quot;a list of words&quot;
258
259        • a-list-of-words
260
261        • a/list/of/words
262
263        • a.list.of.words
264
265        Both parenthesised lists of terms and quoted phrases are ok with proba‐
266        bilistic prefixes such as <b>to:</b>, <b>from:</b>, and <b>subject:</b>. In particular
267
268           subject:(pizza free)
269
270        is equivalent to
271
272           subject:pizza and subject:free
273
274        Both of these will match a subject &quot;Free Delicious Pizza&quot; while
275
276           subject:&quot;pizza free&quot;
277
278        will not.
279 </pre>
280
281 <h3> &nbsp; Quoting</h3>
282 <pre>
283        Double  quotes  are  also  used  by the notmuch query parser to protect
284        boolean terms, regular expressions, or subqueries containing spaces  or
285        other special characters, e.g.
286
287           tag:&quot;a tag&quot;
288
289           folder:&quot;/^.*/(Junk|Spam)$/&quot;
290
291           thread:&quot;{from:mallory and date:2009}&quot;
292
293        As  with  phrases, you need to protect the double quotes from the shell
294        e.g.
295
296           % notmuch search &apos;folder:&quot;/^.*/(Junk|Spam)$/&quot;&apos;
297           % notmuch search &apos;thread:&quot;{from:mallory and date:2009}&quot; and thread:{to:mallory}&apos;
298 </pre>
299
300 <h2>DATE AND TIME SEARCH</h2>
301 <pre>
302        notmuch understands a variety of standard and natural ways of  express‐
303        ing dates and times, both in absolute terms (&quot;2012-10-24&quot;) and in rela‐
304        tive terms (&quot;yesterday&quot;). Any number of relative terms can be  combined
305        (&quot;1  hour  25  minutes&quot;) and an absolute date/time can be combined with
306        relative terms to further adjust it. A  non-exhaustive  description  of
307        the syntax supported for absolute and relative terms is given below.
308 </pre>
309
310 <h3> &nbsp; The range expression</h3>
311 <pre>
312        date:&lt;since&gt;..&lt;until&gt;
313
314        The  above  expression  restricts  the  results  to  only messages from
315        &lt;since&gt; to &lt;until&gt;, based on the Date: header.
316
317        &lt;since&gt; and &lt;until&gt; can describe imprecise times, such as  &quot;yesterday&quot;.
318        In  this  case, &lt;since&gt; is taken as the earliest time it could describe
319        (the beginning of yesterday) and &lt;until&gt; is taken as the latest time it
320        could  describe (the end of yesterday). Similarly, date:january..febru‐
321        ary matches from the beginning of January to the end of February.
322
323        If specifying a time range using timestamps  in  conjunction  with  the
324        date  prefix,  each  timestamp must be preceded by @ (ASCII hex 40). As
325        above, each timestamp is a number representing the  number  of  seconds
326        since 1970-01-01 00:00:00 UTC. For example:
327           date:@&lt;initial-timestamp&gt;..@&lt;final-timestamp&gt;
328
329        Currently,  spaces  in range expressions are not supported. You can re‐
330        place the spaces with &apos;_&apos;, or (in most cases) &apos;-&apos;, or (in  some  cases)
331        leave  the  spaces out altogether. Examples in this man page use spaces
332        for clarity.
333
334        Open-ended  ranges  are  supported.  I.e.  it&apos;s  possible  to   specify
335        date:..&lt;until&gt;  or  date:&lt;since&gt;..  to not limit the start or end time,
336        respectively.
337 </pre>
338
339 <h3> &nbsp; Single expression</h3>
340 <pre>
341        date:&lt;expr&gt; works as a shorthand for date:&lt;expr&gt;..&lt;expr&gt;.  For example,
342        date:monday  matches from the beginning of Monday until the end of Mon‐
343        day.
344 </pre>
345
346 <h3> &nbsp; Relative date and time</h3>
347 <pre>
348        [N|number]         (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
349        onds|secs) [...]
350
351        All refer to past, can be repeated and will be accumulated.
352
353        Units  can  be  abbreviated to any length, with the otherwise ambiguous
354        single m being m for minutes and M for months.
355
356        Number can also be written out one, two, ..., ten, dozen, hundred.  Ad‐
357        ditionally,  the  unit may be preceded by &quot;last&quot; or &quot;this&quot; (e.g., &quot;last
358        week&quot; or &quot;this month&quot;).
359
360        When combined with absolute date and time, the relative date  and  time
361        specification  will  be  relative  from the specified absolute date and
362        time.
363
364        Examples: 5M2d, two weeks
365 </pre>
366
367 <h3> &nbsp; Supported absolute time formats</h3>
368 <pre>
369        • H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
370
371        • H[H] (am|a.m.|pm|p.m.)
372
373        • HHMMSS
374
375        • now
376
377        • noon
378
379        • midnight
380
381        • Examples: 17:05, 5pm
382 </pre>
383
384 <h3> &nbsp; Supported absolute date formats</h3>
385 <pre>
386        • YYYY-MM[-DD]
387
388        • DD-MM[-[YY]YY]
389
390        • MM-YYYY
391
392        • M[M]/D[D][/[YY]YY]
393
394        • M[M]/YYYY
395
396        • D[D].M[M][.[YY]YY]
397
398        • D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
399
400        • Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
401
402        • Wee[kday]
403
404        Month names can be abbreviated at three or more characters.
405
406        Weekday names can be abbreviated at three or more characters.
407
408        Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
409 </pre>
410
411 <h3> &nbsp; Time zones</h3>
412 <pre>
413        • (+|-)HH:MM
414
415        • (+|-)HH[MM]
416
417        Some time zone codes, e.g. UTC, EET.
418 </pre>
419
420 <h2>SEE ALSO</h2>
421 <pre>
422        <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>
423        <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-properties-7/'>notmuch-proper‐</a>
424        <a href='../notmuch-properties-7/'>ties</a>(7), <a href='../notmuch-reindex-1/'>notmuch-reindex</a>(1), <a href='../notmuch-reply-1/'>notmuch-reply</a>(1), <a href='../notmuch-restore-1/'>notmuch-restore</a>(1), <a href='../notmuch-search-1/'>not‐</a>
425        <a href='../notmuch-search-1/'>much-search</a>(1), <a href='../notmuch-show-1/'>notmuch-show</a>(1), <a href='../notmuch-tag-1/'>notmuch-tag</a>(1)
426 </pre>
427
428 <h2>AUTHOR</h2>
429 <pre>
430        Carl Worth and many others
431 </pre>
432
433 <h2>COPYRIGHT</h2>
434 <pre>
435        2009-2022, Carl Worth and many others
436 </pre>
437
438 <h2>0.35</h2>