]> git.cworth.org Git - notmuch-wiki/blob - manpages/notmuch-search-terms-7.mdwn
manpages updates for release 0.28
[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
34        asterisk (&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        If notmuch is built with <b>Xapian</b> <b>Field</b> <b>Processors</b> (see  below)  some  of
44        the  prefixes  with  &lt;regex&gt;  forms  can  be  also used to restrict the
45        results  to  those  whose  value  matches  a  regular  expression  (see
46        <b>regex</b>(7)) delimited with //, for example:
47
48           notmuch search &apos;from:&quot;/bob@.*[.]example[.]com/&quot;&apos;
49
50        <b>from:&lt;name-or-address&gt;</b> <b>or</b> <b>from:/&lt;regex&gt;/</b>
51               The  <b>from:</b>  prefix  is  used to match the name or address of the
52               sender of an email message.
53
54        <b>to:&lt;name-or-address&gt;</b>
55               The <b>to:</b> prefix is used to match the names or  addresses  of  any
56               recipient of an email message, (whether To, Cc, or Bcc).
57
58        <b>subject:&lt;word-or-quoted-phrase&gt;</b> <b>or</b> <b>subject:/&lt;regex&gt;/</b>
59               Any  term  prefixed  with <b>subject:</b> will match only text from the
60               subject of an email. Searching for a phrase in  the  subject  is
61               supported  by including quotation marks around the phrase, imme‐
62               diately following <b>subject:</b>.
63
64        <b>attachment:&lt;word&gt;</b>
65               The <b>attachment:</b> prefix can be used to search for specific  file‐
66               names (or extensions) of attachments to email messages.
67
68        <b>mimetype:&lt;word&gt;</b>
69               The  <b>mimetype:</b>  prefix  will be used to match text from the con‐
70               tent-types of MIME parts within email messages (as specified  by
71               the sender).
72
73        <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>
74               For  <b>tag:</b>  and  <b>is:</b> valid tag values include <b>inbox</b> and <b>unread</b> by
75               default for new messages added by <b>notmuch</b> <b>new</b>  as  well  as  any
76               other tag values added manually with <b>notmuch</b> <b>tag</b>.
77
78        <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>
79               For  <b>id:</b> and <b>mid:</b>, message ID values are the literal contents of
80               the Message-ID: header of email messages, but without  the  &apos;&lt;&apos;,
81               &apos;&gt;&apos; delimiters.
82
83        <b>thread:&lt;thread-id&gt;</b>
84               The  <b>thread:</b>  prefix  can be used with the thread ID values that
85               are generated internally by notmuch (and do not appear in  email
86               messages).  These thread ID values can be seen in the first col‐
87               umn of output from <b>notmuch</b> <b>search</b>
88
89        <b>thread:{&lt;notmuch</b> <b>query&gt;}</b>
90               If notmuch is built with <b>Xapian</b> <b>Field</b>  <b>Processors</b>  (see  below),
91               threads may be searched for indirectly by providing an arbitrary
92               notmuch query in <b>{}</b>. For example, the following returns  threads
93               containing  a  message from mallory and one (not necessarily the
94               same message) with Subject containing the word &quot;crypto&quot;.
95
96                  % notmuch search &apos;thread:&quot;{from:mallory}&quot; and thread:&quot;{subject:crypto}&quot;&apos;
97
98               The performance of such queries can vary wildly.  To  understand
99               this, the user should think of the query <b>thread:{&lt;something&gt;}</b> as
100               expanding to all of the thread IDs which match <b>&lt;something&gt;</b>; not‐
101               much then performs a second search using the expanded query.
102
103        <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>
104               The <b>path:</b> prefix searches for email messages that are in partic‐
105               ular directories within the mail store. The  directory  must  be
106               specified  relative  to  the  top-level maildir (and without the
107               leading slash). By default, <b>path:</b> matches messages in the speci‐
108               fied  directory only. The &quot;/**&quot; suffix can be used to match mes‐
109               sages in the specified  directory  and  all  its  subdirectories
110               recursively.  <b>path:&quot;&quot;</b>  matches  messages in the root of the mail
111               store and, likewise, <b>path:**</b> matches all messages.
112
113               <b>path:</b> will find a message if <u>any</u> copy of that message is in  the
114               specific directory.
115
116        <b>folder:&lt;maildir-folder&gt;</b> <b>or</b> <b>folder:/&lt;regex&gt;/</b>
117               The  <b>folder:</b> prefix searches for email messages by maildir or MH
118               folder. For MH-style folders, this is equivalent to  <b>path:</b>.  For
119               maildir, this includes messages in the &quot;new&quot; and &quot;cur&quot; subdirec‐
120               tories. The exact syntax for maildir  folders  depends  on  your
121               mail  configuration.  For maildir++, <b>folder:&quot;&quot;</b> matches the inbox
122               folder (which is the root  in  maildir++),  other  folder  names
123               always start with &quot;.&quot;, and nested folders are separated by &quot;.&quot;s,
124               such as <b>folder:.classes.topology</b>. For &quot;file system&quot; maildir, the
125               inbox is typically <b>folder:INBOX</b> and nested folders are separated
126               by slashes, such as <b>folder:classes/topology</b>.
127
128               <b>folder:</b> will find a message if <u>any</u> copy of that  message  is  in
129               the specific folder.
130
131        <b>date:&lt;since&gt;..&lt;until&gt;</b> <b>or</b> <b>date:&lt;date&gt;</b>
132               The  <b>date:</b>  prefix  can  be used to restrict the results to only
133               messages within a particular time  range  (based  on  the  Date:
134               header).
135
136               See  <b>DATE</b> <b>AND</b> <b>TIME</b> <b>SEARCH</b> below for details on the range expres‐
137               sion, and supported syntax for &lt;since&gt; and &lt;until&gt; date and time
138               expressions.
139
140               The  time  range  can also be specified using timestamps without
141               including the date prefix using a syntax of:
142
143               &lt;initial-timestamp&gt;..&lt;final-timestamp&gt;
144
145               Each timestamp is a number representing the  number  of  seconds
146               since  1970-01-01 00:00:00 UTC. Specifying a time range this way
147               is considered legacy and predates the date prefix.
148
149        <b>lastmod:&lt;initial-revision&gt;..&lt;final-revision&gt;</b>
150               The <b>lastmod:</b> prefix can be used to restrict the  result  by  the
151               database  revision  number  of  when messages were last modified
152               (tags were added/removed or filenames changed). This is  usually
153               used  in  conjunction with the <b>--uuid</b> argument to <b>notmuch</b> <b>search</b>
154               to find messages that have changed since an earlier query.
155
156        <b>query:&lt;name&gt;</b>
157               The <b>query:</b> prefix allows queries to refer  to  previously  saved
158               queries  added  with  <a href='../notmuch-config-1/'>notmuch-config</a>(1).  Named queries are only
159               available if notmuch is built with <b>Xapian</b> <b>Field</b> <b>Processors</b>  (see
160               below).
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 </pre>
169
170 <h3> &nbsp; Operators</h3>
171 <pre>
172        In  addition  to  individual terms, multiple terms can be combined with
173        Boolean operators (<b>and</b>, <b>or</b>, <b>not</b>, and <b>xor</b>). Each term in the query  will
174        be  implicitly  connected  by  a logical AND if no explicit operator is
175        provided (except that terms with a common  prefix  will  be  implicitly
176        combined  with  OR).   The  shorthand  &apos;-&lt;term&gt;&apos;  can  be used for &apos;not
177        &lt;term&gt;&apos; but unfortunately this does not work at the start of an expres‐
178        sion.   Parentheses  can also be used to control the combination of the
179        Boolean operators, but will have to be protected from interpretation by
180        the shell, (such as by putting quotation marks around any parenthesized
181        expression).
182
183        In addition to the standard boolean operators, Xapian provides  several
184        operators specific to text searching.
185
186           notmuch search term1 NEAR term2
187
188        will  return  results  where  term1  is  within  10 words of term2. The
189        threshold can be set like this:
190
191           notmuch search term1 NEAR/2 term2
192
193        The search
194
195           notmuch search term1 ADJ term2
196
197        will return results where term1 is within 10 words of term2, but in the
198        same  order  as in the query. The threshold can be set the same as with
199        NEAR:
200
201           notmuch search term1 ADJ/7 term2
202 </pre>
203
204 <h3> &nbsp; Stemming</h3>
205 <pre>
206        <b>Stemming</b> 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  &quot;reduces&quot;  the
213        term to the common stem (here &apos;detail&apos;) 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 &quot;John&quot; and  not
217        get  results  for  &quot;Johnson&quot;;  phrase  searches are also unstemmed (see
218        below for details).  Stemming is currently only supported for  English.
219        Searches for words in other languages will be performed unstemmed.
220 </pre>
221
222 <h3> &nbsp; Wildcards</h3>
223 <pre>
224        It  is  possible  to  use  a  trailing  &apos;*&apos; as a wildcard. A search for
225        &apos;wildc*&apos; will match &apos;wildcard&apos;, &apos;wildcat&apos;, etc.
226 </pre>
227
228 <h3> &nbsp; Boolean and Probabilistic Prefixes</h3>
229 <pre>
230        Xapian (and hence notmuch)  prefixes  are  either  <b>boolean</b>,  supporting
231        exact  matches  like  &quot;<u>tag:inbox</u>&quot;  or  <b>probabilistic</b>, supporting a more
232        flexible <b>term</b> based searching. Certain <b>special</b> prefixes  are  processed
233        by  notmuch  in  a way not strictly fitting either of Xapian&apos;s built in
234        styles. The prefixes currently supported by notmuch are as follows.
235
236        <b>Boolean</b>
237               <b>tag:</b>, <b>id:</b>, <b>thread:</b>, <b>folder:</b>, <b>path:</b>, <b>property:</b>
238
239        <b>Probabilistic</b>
240               <b>to:</b>, <b>attachment:</b>, <b>mimetype:</b>
241
242        <b>Special</b>
243               <b>from:</b>, <b>query:</b>, <b>subject:</b>
244 </pre>
245
246 <h3> &nbsp; Terms and phrases</h3>
247 <pre>
248        In general Xapian distinguishes between lists  of  terms  and  <b>phrases</b>.
249        Phrases are indicated by double quotes (but beware you probably need to
250        protect those from your shell) and insist that  those  unstemmed  words
251        occur  in  that  order. One useful, but initially surprising feature is
252        that the following are equivalent ways to write the same phrase.
253
254        · &quot;a list of words&quot;
255
256        · a-list-of-words
257
258        · a/list/of/words
259
260        · a.list.of.words
261
262        Both parenthesised lists of terms and quoted phrases are ok with proba‐
263        bilistic prefixes such as <b>to:</b>, <b>from:</b>, and <b>subject:</b>. In particular
264
265           subject:(pizza free)
266
267        is equivalent to
268
269           subject:pizza and subject:free
270
271        Both of these will match a subject &quot;Free Delicious Pizza&quot; while
272
273           subject:&quot;pizza free&quot;
274
275        will not.
276 </pre>
277
278 <h3> &nbsp; Quoting</h3>
279 <pre>
280        Double  quotes  are  also  used  by the notmuch query parser to protect
281        boolean terms, regular expressions, or subqueries containing spaces  or
282        other special characters, e.g.
283
284           tag:&quot;a tag&quot;
285
286           folder:&quot;/^.*/(Junk|Spam)$/&quot;
287
288           thread:&quot;{from:mallory and date:2009}&quot;
289
290        As  with  phrases, you need to protect the double quotes from the shell
291        e.g.
292
293           % notmuch search &apos;folder:&quot;/^.*/(Junk|Spam)$/&quot;&apos;
294           % notmuch search &apos;thread:&quot;{from:mallory and date:2009}&quot; and thread:{to:mallory}&apos;
295 </pre>
296
297 <h2>DATE AND TIME SEARCH</h2>
298 <pre>
299        notmuch understands a variety of standard and natural ways of  express‐
300        ing dates and times, both in absolute terms (&quot;2012-10-24&quot;) and in rela‐
301        tive terms (&quot;yesterday&quot;). Any number of relative terms can be  combined
302        (&quot;1  hour  25  minutes&quot;) and an absolute date/time can be combined with
303        relative terms to further adjust it. A  non-exhaustive  description  of
304        the syntax supported for absolute and relative terms is given below.
305 </pre>
306
307 <h3> &nbsp; The range expression</h3>
308 <pre>
309        date:&lt;since&gt;..&lt;until&gt;
310
311        The  above  expression  restricts  the  results  to  only messages from
312        &lt;since&gt; to &lt;until&gt;, based on the Date: header.
313
314        &lt;since&gt; and &lt;until&gt; can describe imprecise times, such as  &quot;yesterday&quot;.
315        In  this  case, &lt;since&gt; is taken as the earliest time it could describe
316        (the beginning of yesterday) and &lt;until&gt; is taken as the latest time it
317        could  describe (the end of yesterday). Similarly, date:january..febru‐
318        ary matches from the beginning of January to the end of February.
319
320        If specifying a time range using timestamps  in  conjunction  with  the
321        date  prefix,  each  timestamp must be preceded by @ (ASCII hex 40). As
322        above, each timestamp is a number representing the  number  of  seconds
323        since 1970-01-01 00:00:00 UTC. For example:
324           date:@&lt;initial-timestamp&gt;..@&lt;final-timestamp&gt;
325
326        date:&lt;expr&gt;..!  can be used as a shorthand for date:&lt;expr&gt;..&lt;expr&gt;. The
327        expansion takes place before interpretation,  and  thus,  for  example,
328        date:monday..!  matches  from  the beginning of Monday until the end of
329        Monday.  With <b>Xapian</b> <b>Field</b> <b>Processor</b>  support  (see  below),  non-range
330        date  queries such as date:yesterday will work, but otherwise will give
331        unexpected results; if in doubt use date:yesterday..!
332
333        Currently, we do not support  spaces  in  range  expressions.  You  can
334        replace the spaces with &apos;_&apos;, or (in most cases) &apos;-&apos;, or (in some cases)
335        leave the spaces out altogether. Examples in this man page  use  spaces
336        for clarity.
337
338        Open-ended  ranges are supported (since Xapian 1.2.1), i.e. it&apos;s possi‐
339        ble to specify date:..&lt;until&gt; or date:&lt;since&gt;.. to not limit the  start
340        or end time, respectively. Pre-1.2.1 Xapian does not report an error on
341        open ended ranges, but it does not work as expected either.
342 </pre>
343
344 <h3> &nbsp; Relative date and time</h3>
345 <pre>
346        [N|number]         (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
347        onds|secs) [...]
348
349        All refer to past, can be repeated and will be accumulated.
350
351        Units  can  be  abbreviated to any length, with the otherwise ambiguous
352        single m being m for minutes and M for months.
353
354        Number can also be written out one,  two,  ...,  ten,  dozen,  hundred.
355        Additionally, the unit may be preceded by &quot;last&quot; or &quot;this&quot; (e.g., &quot;last
356        week&quot; or &quot;this month&quot;).
357
358        When combined with absolute date and time, the relative date  and  time
359        specification  will  be  relative  from the specified absolute date and
360        time.
361
362        Examples: 5M2d, two weeks
363 </pre>
364
365 <h3> &nbsp; Supported absolute time formats</h3>
366 <pre>
367        · H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
368
369        · H[H] (am|a.m.|pm|p.m.)
370
371        · HHMMSS
372
373        · now
374
375        · noon
376
377        · midnight
378
379        · Examples: 17:05, 5pm
380 </pre>
381
382 <h3> &nbsp; Supported absolute date formats</h3>
383 <pre>
384        · YYYY-MM[-DD]
385
386        · DD-MM[-[YY]YY]
387
388        · MM-YYYY
389
390        · M[M]/D[D][/[YY]YY]
391
392        · M[M]/YYYY
393
394        · D[D].M[M][.[YY]YY]
395
396        · D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
397
398        · Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
399
400        · Wee[kday]
401
402        Month names can be abbreviated at three or more characters.
403
404        Weekday names can be abbreviated at three or more characters.
405
406        Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
407 </pre>
408
409 <h3> &nbsp; Time zones</h3>
410 <pre>
411        · (+|-)HH:MM
412
413        · (+|-)HH[MM]
414
415        Some time zone codes, e.g. UTC, EET.
416 </pre>
417
418 <h2>XAPIAN FIELD PROCESSORS</h2>
419 <pre>
420        Certain optional features of the notmuch query processor  rely  on  the
421        presence  of  the Xapian field processor API. You can determine if your
422        notmuch was built against a sufficiently recent version  of  Xapian  by
423        running
424
425           % notmuch config get built_with.field_processor
426
427        Currently the following features require field processor support:
428
429        · non-range date queries, e.g. &quot;date:today&quot;
430
431        · named queries e.g. &quot;query:my_special_query&quot;
432
433        · regular expression searches, e.g. &quot;subject:/^\[SPAM\]/&quot;
434
435        · thread subqueries, e.g. &quot;thread:{from:bob}&quot;
436 </pre>
437
438 <h2>SEE ALSO</h2>
439 <pre>
440        <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>
441        <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),
442        <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>
443        <a href='../notmuch-search-1/'>much-search</a>(1), <b>*notmuch-show</b>(1), <a href='../notmuch-tag-1/'>notmuch-tag</a>(1)
444 </pre>
445
446 <h2>AUTHOR</h2>
447 <pre>
448        Carl Worth and many others
449 </pre>
450
451 <h2>COPYRIGHT</h2>
452 <pre>
453        2009-2018, Carl Worth and many others
454 </pre>
455
456 <h2>0.28</h2>