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