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