]> git.notmuchmail.org Git - notmuch/blob - doc/man7/notmuch-search-terms.rst
doc: typo fix for prefix discussion.
[notmuch] / doc / man7 / notmuch-search-terms.rst
1 ====================
2 notmuch-search-terms
3 ====================
4
5 SYNOPSIS
6 ========
7
8 **notmuch** **count** [option ...] <*search-term*> ...
9
10 **notmuch** **dump** [--format=(batch-tag|sup)] [--] [--output=<*file*>] [--] [<*search-term*> ...]
11
12 **notmuch** **search** [option ...] <*search-term*> ...
13
14 **notmuch** **show** [option ...] <*search-term*> ...
15
16 **notmuch** **tag** +<*tag*> ... -<*tag*> [--] <*search-term*> ...
17
18 DESCRIPTION
19 ===========
20
21 Several notmuch commands accept a common syntax for search terms.
22
23 The search terms can consist of free-form text (and quoted phrases)
24 which will match all messages that contain all of the given
25 terms/phrases in the body, the subject, or any of the sender or
26 recipient headers.
27
28 As a special case, a search string consisting of exactly a single
29 asterisk ("\*") will match all messages.
30
31 In addition to free text, the following prefixes can be used to force
32 terms to match against specific portions of an email, (where <brackets>
33 indicate user-supplied values):
34
35 -  from:<name-or-address>
36
37 -  to:<name-or-address>
38
39 -  subject:<word-or-quoted-phrase>
40
41 -  attachment:<word>
42
43 -  mimetype:<word>
44
45 -  tag:<tag> (or is:<tag>)
46
47 -  id:<message-id>
48
49 -  thread:<thread-id>
50
51 -  folder:<maildir-folder>
52
53 -  path:<directory-path> or path:<directory-path>/**
54
55 -  date:<since>..<until>
56
57 The **from:** prefix is used to match the name or address of the sender
58 of an email message.
59
60 The **to:** prefix is used to match the names or addresses of any
61 recipient of an email message, (whether To, Cc, or Bcc).
62
63 Any term prefixed with **subject:** will match only text from the
64 subject of an email. Searching for a phrase in the subject is supported
65 by including quotation marks around the phrase, immediately following
66 **subject:**.
67
68 The **attachment:** prefix can be used to search for specific filenames
69 (or extensions) of attachments to email messages.
70
71 The **mimetype:** prefix will be used to match text from the
72 content-types of MIME parts within email messages (as specified by the
73 sender).
74
75 For **tag:** and **is:** valid tag values include **inbox** and
76 **unread** by default for new messages added by **notmuch new** as well
77 as any other tag values added manually with **notmuch tag**.
78
79 For **id:**, message ID values are the literal contents of the
80 Message-ID: header of email messages, but without the '<', '>'
81 delimiters.
82
83 The **thread:** prefix can be used with the thread ID values that are
84 generated internally by notmuch (and do not appear in email messages).
85 These thread ID values can be seen in the first column of output from
86 **notmuch search**
87
88 The **path:** prefix searches for email messages that are in
89 particular directories within the mail store. The directory must be
90 specified relative to the top-level maildir (and without the leading
91 slash). By default, **path:** matches messages in the specified
92 directory only. The "/\*\*" suffix can be used to match messages in
93 the specified directory and all its subdirectories recursively.
94 **path:""** matches messages in the root of the mail store and,
95 likewise, **path:\*\*** matches all messages.
96
97 The **folder:** prefix searches for email messages by maildir or MH
98 folder. For MH-style folders, this is equivalent to **path:**. For
99 maildir, this includes messages in the "new" and "cur"
100 subdirectories. The exact syntax for maildir folders depends on your
101 mail configuration. For maildir++, **folder:""** matches the inbox
102 folder (which is the root in maildir++), other folder names always
103 start with ".", and nested folders are separated by "."s, such as
104 **folder:.classes.topology**. For "file system" maildir, the inbox is
105 typically **folder:INBOX** and nested folders are separated by
106 slashes, such as **folder:classes/topology**.
107
108 Both **path:** and **folder:** will find a message if *any* copy of
109 that message is in the specific directory/folder.
110
111 The **date:** prefix can be used to restrict the results to only
112 messages within a particular time range (based on the Date: header) with
113 a range syntax of:
114
115 date:<since>..<until>
116
117 See **DATE AND TIME SEARCH** below for details on the range expression,
118 and supported syntax for <since> and <until> date and time expressions.
119
120 The time range can also be specified using timestamps with a syntax of:
121
122 <initial-timestamp>..<final-timestamp>
123
124 Each timestamp is a number representing the number of seconds since
125 1970-01-01 00:00:00 UTC.
126
127 Operators
128 ---------
129
130 In addition to individual terms, multiple terms can be combined with
131 Boolean operators (**and**, **or**, **not**, and **xor**). Each term
132 in the query will be implicitly connected by a logical AND if no
133 explicit operator is provided (except that terms with a common prefix
134 will be implicitly combined with OR).  The shorthand '-<term>' can be
135 used for 'not <term>' but unfortunately this does not work at the
136 start of an expression.  Parentheses can also be used to control the
137 combination of the Boolean operators, but will have to be protected
138 from interpretation by the shell, (such as by putting quotation marks
139 around any parenthesized expression).
140
141 In addition to the standard boolean operators, Xapian provides several
142 operators specific to text searching.
143
144 ::
145
146         notmuch search term1 NEAR term2
147
148 will return results where term1 is within 10 words of term2. The
149 threshold can be set like this:
150
151 ::
152
153         notmuch search term1 NEAR/2 term2
154
155 The search
156
157 ::
158
159         notmuch search term1 ADJ term2
160
161 will return results where term1 is within 10 words of term2, but in the
162 same order as in the query. The threshold can be set the same as with
163 NEAR:
164
165 ::
166
167         notmuch search term1 ADJ/7 term2
168
169
170 Stemming
171 --------
172
173 **Stemming** in notmuch means that these searches
174
175 ::
176
177         notmuch search detailed
178         notmuch search details
179         notmuch search detail
180
181 will all return identical results, because Xapian first "reduces" the
182 term to the common stem (here 'detail') and then performs the search.
183
184 There are two ways to turn this off: a search for a capitalized word
185 will be performed unstemmed, so that one can search for "John" and not
186 get results for "Johnson"; phrase searches are also unstemmed (see
187 below for details).  Stemming is currently only supported for
188 English. Searches for words in other languages will be performed unstemmed.
189
190 Wildcards
191 ---------
192
193 It is possible to use a trailing '\*' as a wildcard. A search for
194 'wildc\*' will match 'wildcard', 'wildcat', etc.
195
196
197 Boolean and Probabilistic Prefixes
198 ----------------------------------
199
200 Xapian (and hence notmuch) prefixes are either **boolean**, supporting
201 exact matches like "tag:inbox"  or **probabilistic**, supporting a more flexible **term** based searching. The prefixes currently supported by notmuch are as follows.
202
203 +------------------+-----------------------+
204 |Boolean           |Probabilistic          |
205 +------------------+-----------------------+
206 | **tag:** **id:** | **from:** **to:**     |
207 |**thread:**       |**subject:**           |
208 |**folder:**       |**attachment**         |
209 |**path:**         |                       |
210 |                  |                       |
211 +------------------+-----------------------+
212
213 Terms and phrases
214 -----------------
215
216 In general Xapian distinguishes between lists of terms and
217 **phrases**. Phrases are indicated by double quotes (but beware you
218 probably need to protect those from your shell) and insist that those
219 unstemmed words occur in that order. One useful, but initially
220 surprising feature is that the following are equivalant ways to write
221 the same phrase.
222
223 - "a list of words"
224 - a-list-of-words
225 - a/list/of/words
226 - a.list.of.words
227
228 Both parenthesised lists of terms and quoted phrases are ok with
229 probabilisitic prefixes such as **to:**, **from:**, and **subject:**. In particular
230
231 ::
232
233    subject:(pizza free)
234
235 is equivalent to
236
237 ::
238
239    subject:pizza and subject:free
240
241 Both of these will match a subject "Free Delicious Pizza" while
242
243 ::
244
245    subject:"pizza free"
246
247 will not.
248
249 DATE AND TIME SEARCH
250 ====================
251
252 notmuch understands a variety of standard and natural ways of expressing
253 dates and times, both in absolute terms ("2012-10-24") and in relative
254 terms ("yesterday"). Any number of relative terms can be combined ("1
255 hour 25 minutes") and an absolute date/time can be combined with
256 relative terms to further adjust it. A non-exhaustive description of the
257 syntax supported for absolute and relative terms is given below.
258
259 The range expression
260 --------------------
261
262 date:<since>..<until>
263
264 The above expression restricts the results to only messages from <since>
265 to <until>, based on the Date: header.
266
267 <since> and <until> can describe imprecise times, such as "yesterday".
268 In this case, <since> is taken as the earliest time it could describe
269 (the beginning of yesterday) and <until> is taken as the latest time it
270 could describe (the end of yesterday). Similarly, date:january..february
271 matches from the beginning of January to the end of February.
272
273 Currently, we do not support spaces in range expressions. You can
274 replace the spaces with '\_', or (in most cases) '-', or (in some cases)
275 leave the spaces out altogether. Examples in this man page use spaces
276 for clarity.
277
278 Open-ended ranges are supported (since Xapian 1.2.1), i.e. it's possible
279 to specify date:..<until> or date:<since>.. to not limit the start or
280 end time, respectively. Pre-1.2.1 Xapian does not report an error on
281 open ended ranges, but it does not work as expected either.
282
283 Entering date:expr without ".." (for example date:yesterday) won't work,
284 as it's not interpreted as a range expression at all. You can achieve
285 the expected result by duplicating the expr both sides of ".." (for
286 example date:yesterday..yesterday).
287
288 Relative date and time
289 ----------------------
290
291 [N\|number]
292 (years\|months\|weeks\|days\|hours\|hrs\|minutes\|mins\|seconds\|secs)
293 [...]
294
295 All refer to past, can be repeated and will be accumulated.
296
297 Units can be abbreviated to any length, with the otherwise ambiguous
298 single m being m for minutes and M for months.
299
300 Number can also be written out one, two, ..., ten, dozen, hundred.
301 Additionally, the unit may be preceded by "last" or "this" (e.g., "last
302 week" or "this month").
303
304 When combined with absolute date and time, the relative date and time
305 specification will be relative from the specified absolute date and
306 time.
307
308 Examples: 5M2d, two weeks
309
310 Supported absolute time formats
311 -------------------------------
312
313 -  H[H]:MM[:SS] [(am\|a.m.\|pm\|p.m.)]
314
315 -  H[H] (am\|a.m.\|pm\|p.m.)
316
317 -  HHMMSS
318
319 -  now
320
321 -  noon
322
323 -  midnight
324
325 -  Examples: 17:05, 5pm
326
327 Supported absolute date formats
328 -------------------------------
329
330 -  YYYY-MM[-DD]
331
332 -  DD-MM[-[YY]YY]
333
334 -  MM-YYYY
335
336 -  M[M]/D[D][/[YY]YY]
337
338 -  M[M]/YYYY
339
340 -  D[D].M[M][.[YY]YY]
341
342 -  D[D][(st\|nd\|rd\|th)] Mon[thname] [YYYY]
343
344 -  Mon[thname] D[D][(st\|nd\|rd\|th)] [YYYY]
345
346 -  Wee[kday]
347
348 Month names can be abbreviated at three or more characters.
349
350 Weekday names can be abbreviated at three or more characters.
351
352 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
353
354 Time zones
355 ----------
356
357 -  (+\|-)HH:MM
358
359 -  (+\|-)HH[MM]
360
361 Some time zone codes, e.g. UTC, EET.
362
363 SEE ALSO
364 ========
365
366 **notmuch(1)**, **notmuch-config(1)**, **notmuch-count(1)**,
367 **notmuch-dump(1)**, **notmuch-hooks(5)**, **notmuch-insert(1)**,
368 **notmuch-new(1)**, **notmuch-reply(1)**, **notmuch-restore(1)**,
369 **notmuch-search(1)**, **notmuch-show(1)**, **notmuch-tag(1)**