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