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