1 # Searching with notmuch
3 What good is an advanced indexing mail client if we don't know how to
4 use it to actually find e-mail?
6 As notmuch is using Xapian
7 [this page](http://xapian.org/docs/queryparser.html) is a good start.
8 However, the description is generic (applies to Xapian in general) and
9 its intended audience seems to be developers wanting to use Xapian in
10 their applications. This page attempts to explain it to users of notmuch (who
11 may not be familiar with Xapian). 'notmuch help search-terms' also has a few
16 See the [Wikipedia article](http://en.wikipedia.org/wiki/Stemming) for
17 the detailed description. What this means for us is that these searches
19 notmuch search detailed
20 notmuch search details
23 will all return identical results, because Xapian first "reduces" the
24 term to the common stem (here 'detail') and then performs the search.
26 The only way to turn this off is the so called search for proper names:
27 a search for a capitalized word will be performed unstemmed, so that one
28 can search for "John" and not get results for "Johnson".
30 ### Languages other than English
32 Stemming is currently only supported for English. Words in other
33 languages will be performed unstemmed unless somebody teaches Xapian how
34 to perform stemming for that language.
38 (how is the QueryParser configured?)
42 It is possible to use a trailing '\*' as a wildcard. A search for
43 'wildc\*' will match 'wildcard', 'wildcat', etc.
47 Xapian implements the usual operators and a few more that are
48 useful when searching e-mails.
50 *Note: The operators need not be capitalized for notmuch, so 'NOT' and 'not' are
51 equivalent. The capitalized form is used below only for readability*
57 will only return results that contain 'term1'.
61 will return results that do not contain 'term2'. '+' and '-' can also be
62 used on bracketed expressions or phrases (see below).
66 notmuch search term1 AND term2
68 will return results that contain **both** 'term1' and 'term2'.
70 If no explicit operator is provided all search terms are connected by an
71 implicit AND, so these two searches:
73 notmuch search term1 AND term2
74 notmuch search term1 term2
78 notmuch search term1 NOT term2
80 will return results that contain 'term1' but do not contain 'term2'. For
81 a query that looks more like natural language you can also use AND NOT
83 notmuch search term1 AND NOT term2
85 ### XOR (exclusive OR)
87 notmuch search term1 XOR term2
89 will return results that contain either 'term1' or 'term2', but **not**
94 notmuch search term1 OR term2
96 will return results that contain either 'term1' or 'term2'.
100 Operators above are listed in the default order of precedence. One can
101 override the precedence using bracketed expressions:
103 notmuch search term1 AND term2 OR term3
107 notmuch search (term1 AND term2) OR term3
111 notmuch search term1 AND (term2 OR term3)
115 notmuch search term1 NEAR term2
117 will return results where term1 is within 10 words of term2. The threshold
118 can be set like this:
120 notmuch search term1 NEAR/2 term2
124 notmuch search term1 ADJ term2
126 will return results where term1 is within 10 words of term2, but in the
127 same order as in the query. The threshold can be set the same as with NEAR:
129 notmuch search term1 ADJ/7 term2
133 According to the Xapian documentation a phrase surrounded with double
134 quotes (like this: "my phrase") will return results that match
135 everything containing "that exact phrase", but hyphenated words or
136 e-mail addresses are also treated as phrases.
138 In practice this means that these two searches are **not** equivalent:
140 notmuch search "Debian Project"
141 notmuch search Debian ADJ/1 Project
145 You can search your collection by using several prefixes, like this:
147 notmuch search from:john
149 This will return results where 'john' appears in the name or the e-mail
150 address. See 'notmuch help search-terms' for a complete list of
155 An important concept for notmuch is the Message-Id, which is a unique
156 identifier for each message. Individual messages can be accessed via
157 their message ID with the "id:" prefix:
159 notmuch search id:<message-id>
163 Since notmuch is about (large) e-mail collections it is very useful to
164 be able to search for e-mails within a specific date range. This will
167 notmuch search <initial timestamp>..<final-timestamp>
169 However, until a better syntax is implemented the only form accepted for
170 timestamps is Unix time (seconds since 1970-01-01 00:00:00 UTC), so the
171 utility 'date' can help:
173 notmuch search $(date +%s -d 2009-10-01)..$(date +%s)
175 Explanation: '+%s' will tell date to output Unix time format and -d will
176 tell date to output the date from 2009-10-01. See date(1) for more