1 Return-Path: <amdragon@mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1C6E7431FAF
\r
6 for <notmuch@notmuchmail.org>; Mon, 22 Oct 2012 21:53:00 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id xoZ8QlF+4ryi for <notmuch@notmuchmail.org>;
\r
16 Mon, 22 Oct 2012 21:52:57 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id AF744431FAE
\r
20 for <notmuch@notmuchmail.org>; Mon, 22 Oct 2012 21:52:57 -0700 (PDT)
\r
21 X-AuditID: 12074424-b7fce6d000000925-80-508622a9131f
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 6C.00.02341.9A226805; Tue, 23 Oct 2012 00:52:57 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q9N4qv4f005920;
\r
27 Tue, 23 Oct 2012 00:52:57 -0400
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q9N4qtWK000615
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Tue, 23 Oct 2012 00:52:56 -0400 (EDT)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1TQWU3-0001lP-FG; Tue, 23 Oct 2012 00:52:55 -0400
\r
37 Date: Tue, 23 Oct 2012 00:52:55 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: Jani Nikula <jani@nikula.org>
\r
40 Subject: Re: [PATCH v5 6/9] lib: add date range query support
\r
41 Message-ID: <20121023045255.GQ14861@mit.edu>
\r
42 References: <cover.1350854171.git.jani@nikula.org>
\r
43 <f21b8702728457c087478b26700e9448bc16c61d.1350854171.git.jani@nikula.org>
\r
45 Content-Type: text/plain; charset=us-ascii
\r
46 Content-Disposition: inline
\r
48 <f21b8702728457c087478b26700e9448bc16c61d.1350854171.git.jani@nikula.org>
\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
50 X-Brightmail-Tracker:
\r
51 H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IR4hRV1l2p1BZg8HKpiEXTdGeL6zdnMjsw
\r
52 edy6/5rd49mqW8wBTFFcNimpOZllqUX6dglcGe8+9zEWrDCp2HZjEXsD416tLkZODgkBE4n1
\r
53 px+yQ9hiEhfurWfrYuTiEBLYxyjRs/g9I4SzgVHiw6zXUJmTTBIn5r+AyixhlFh38QITSD+L
\r
54 gKrE9l+HWEBsNgENiW37lzOC2CICihKbT+4Hs5kFpCW+/W4GqxcWsJWY/XwB2G5eAR2Jy7MX
\r
55 gdUICdRJTHx1jAkiLihxcuYTFoheLYkb/14CxTnA5iz/xwFicgqESTzYVwNSISqgIjHl5Da2
\r
56 CYxCs5A0z0LSPAuheQEj8ypG2ZTcKt3cxMyc4tRk3eLkxLy81CJdc73czBK91JTSTYygoGZ3
\r
57 UdnB2HxI6RCjAAejEg+vwd7WACHWxLLiytxDjJIcTEqivC6SbQFCfEn5KZUZicUZ8UWlOanF
\r
58 hxglOJiVRHiVA4DKeVMSK6tSi/JhUtIcLErivNdTbvoLCaQnlqRmp6YWpBbBZGU4OJQkeI8o
\r
59 Ag0VLEpNT61Iy8wpQUgzcXCCDOcBGi4PTAJCvMUFibnFmekQ+VOMilLivFdBmgVAEhmleXC9
\r
60 sKTzilEc6BVh3teiQFU8wIQF1/0KaDAT0GBzHpCri0sSEVJSDYyuhQrth1KZpoaxzzM4Jnvl
\r
61 U76xxWGrqnjTP9y33bykkiV8XvR+3S4XvbzK84lpSFdXQrPQLoslpjNLZ0e8CDS+vqwn9m/h
\r
62 y9gdT0Pv1XmtX7okdV6Hcvoe++Qf6ctF7qTXXPwdZRJnFXaW5/R9Romybo6W7xLnA1j2xmrk
\r
63 7tbJ/bfwUrrEZyWW4oxEQy3mouJEAMsXl9sVAwAA
\r
64 Cc: notmuch@notmuchmail.org
\r
65 X-BeenThere: notmuch@notmuchmail.org
\r
66 X-Mailman-Version: 2.1.13
\r
68 List-Id: "Use and development of the notmuch mail system."
\r
69 <notmuch.notmuchmail.org>
\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
73 List-Post: <mailto:notmuch@notmuchmail.org>
\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
76 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
77 X-List-Received-Date: Tue, 23 Oct 2012 04:53:00 -0000
\r
79 Quoth Jani Nikula on Oct 22 at 12:22 am:
\r
80 > Add a custom value range processor to enable date and time searches of
\r
81 > the form date:since..until, where "since" and "until" are expressions
\r
82 > understood by the previously added date/time parser, to restrict the
\r
83 > results to messages within a particular time range (based on the Date:
\r
86 > If "since" or "until" describes date/time at an accuracy of days or
\r
87 > less, the values are rounded according to the accuracy, towards past
\r
88 > for "since" and towards future for "until". For example,
\r
89 > date:november..yesterday would match from the beginning of November
\r
90 > until the end of yesterday. Expressions such as date:today..today
\r
91 > means since the beginning of today until the end of today.
\r
93 > Open-ended ranges are supported (since Xapian 1.2.1), i.e. you can
\r
94 > specify date:..until or date:since.. to not limit the start or end
\r
95 > date, respectively.
\r
99 > Xapian does not support spaces in range expressions. You can replace
\r
100 > the spaces with '_', or (in most cases) '-', or (in some cases) leave
\r
101 > the spaces out altogether.
\r
103 > Entering date:expr without ".." (for example date:yesterday) will not
\r
104 > work as you might expect. You can achieve the expected result by
\r
105 > duplicating the expr both sides of ".." (for example
\r
106 > date:yesterday..yesterday).
\r
108 > Open-ended ranges won't work with pre-1.2.1 Xapian, but they don't
\r
109 > produce an error either.
\r
111 > Signed-off-by: Jani Nikula <jani@nikula.org>
\r
113 > lib/Makefile.local | 1 +
\r
114 > lib/database-private.h | 1 +
\r
115 > lib/database.cc | 5 +++++
\r
116 > lib/parse-time-vrp.cc | 40 ++++++++++++++++++++++++++++++++++++++++
\r
117 > lib/parse-time-vrp.h | 19 +++++++++++++++++++
\r
118 > 5 files changed, 66 insertions(+)
\r
119 > create mode 100644 lib/parse-time-vrp.cc
\r
120 > create mode 100644 lib/parse-time-vrp.h
\r
122 > diff --git a/lib/Makefile.local b/lib/Makefile.local
\r
123 > index d1635cf..6c0f42f 100644
\r
124 > --- a/lib/Makefile.local
\r
125 > +++ b/lib/Makefile.local
\r
126 > @@ -58,6 +58,7 @@ libnotmuch_c_srcs = \
\r
128 > libnotmuch_cxx_srcs = \
\r
129 > $(dir)/database.cc \
\r
130 > + $(dir)/parse-time-vrp.cc \
\r
131 > $(dir)/directory.cc \
\r
132 > $(dir)/index.cc \
\r
133 > $(dir)/message.cc \
\r
134 > diff --git a/lib/database-private.h b/lib/database-private.h
\r
135 > index 88532d5..d3e65fd 100644
\r
136 > --- a/lib/database-private.h
\r
137 > +++ b/lib/database-private.h
\r
138 > @@ -52,6 +52,7 @@ struct _notmuch_database {
\r
139 > Xapian::QueryParser *query_parser;
\r
140 > Xapian::TermGenerator *term_gen;
\r
141 > Xapian::ValueRangeProcessor *value_range_processor;
\r
142 > + Xapian::ValueRangeProcessor *date_range_processor;
\r
145 > /* Return the list of terms from the given iterator matching a prefix.
\r
146 > diff --git a/lib/database.cc b/lib/database.cc
\r
147 > index 761dc1a..4df3217 100644
\r
148 > --- a/lib/database.cc
\r
149 > +++ b/lib/database.cc
\r
150 > @@ -19,6 +19,7 @@
\r
153 > #include "database-private.h"
\r
154 > +#include "parse-time-vrp.h"
\r
156 > #include <iostream>
\r
158 > @@ -710,12 +711,14 @@ notmuch_database_open (const char *path,
\r
159 > notmuch->term_gen = new Xapian::TermGenerator;
\r
160 > notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
\r
161 > notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
\r
162 > + notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
\r
164 > notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
\r
165 > notmuch->query_parser->set_database (*notmuch->xapian_db);
\r
166 > notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));
\r
167 > notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
\r
168 > notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
\r
169 > + notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);
\r
171 > for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
\r
172 > prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
\r
173 > @@ -778,6 +781,8 @@ notmuch_database_close (notmuch_database_t *notmuch)
\r
174 > notmuch->xapian_db = NULL;
\r
175 > delete notmuch->value_range_processor;
\r
176 > notmuch->value_range_processor = NULL;
\r
177 > + delete notmuch->date_range_processor;
\r
178 > + notmuch->date_range_processor = NULL;
\r
182 > diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc
\r
183 > new file mode 100644
\r
184 > index 0000000..7e4eca4
\r
186 > +++ b/lib/parse-time-vrp.cc
\r
189 Should this file have the usual preamble?
\r
192 > +#include "database-private.h"
\r
193 > +#include "parse-time-vrp.h"
\r
194 > +#include "parse-time-string.h"
\r
196 > +#define PREFIX "date:"
\r
198 > +/* See *ValueRangeProcessor in xapian-core/api/valuerangeproc.cc */
\r
200 > +ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)
\r
204 > + /* Require date: prefix in start of the range... */
\r
205 > + if (STRNCMP_LITERAL (begin.c_str (), PREFIX))
\r
208 if (begin.rfind (PREFIX, 0) == string::npos)
\r
209 but that may not be clearer.
\r
211 > + return Xapian::BAD_VALUENO;
\r
213 > + /* ...and remove it. */
\r
214 > + begin.erase (0, sizeof (PREFIX) - 1);
\r
216 > + /* Use the same 'now' for begin and end. */
\r
217 > + if (time (&now) == (time_t) -1)
\r
218 > + return Xapian::BAD_VALUENO;
\r
220 > + if (!begin.empty ()) {
\r
221 > + if (parse_time_string (begin.c_str (), &t, &now, PARSE_TIME_ROUND_DOWN))
\r
222 > + return Xapian::BAD_VALUENO;
\r
224 > + begin.assign (Xapian::sortable_serialise ((double) t));
\r
227 > + if (!end.empty ()) {
\r
228 > + if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))
\r
229 > + return Xapian::BAD_VALUENO;
\r
231 > + end.assign (Xapian::sortable_serialise ((double) t));
\r
236 > diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h
\r
237 > new file mode 100644
\r
238 > index 0000000..526c217
\r
240 > +++ b/lib/parse-time-vrp.h
\r
243 Same thing about the preamble.
\r
246 > +#ifndef NOTMUCH_PARSE_TIME_VRP_H
\r
247 > +#define NOTMUCH_PARSE_TIME_VRP_H
\r
249 > +#include <xapian.h>
\r
251 > +/* see *ValueRangeProcessor in xapian-core/include/xapian/queryparser.h */
\r
253 Out of curiosity, why the Xapian source reference?
\r
254 ValueRangeProcessor is documented along the rest of Xapian.
\r
256 > +class ParseTimeValueRangeProcessor : public Xapian::ValueRangeProcessor {
\r
258 > + Xapian::valueno valno;
\r
261 > + ParseTimeValueRangeProcessor (Xapian::valueno slot_)
\r
262 > + : valno(slot_) { }
\r
264 > + Xapian::valueno operator() (std::string &begin, std::string &end);
\r
267 > +#endif /* NOTMUCH_PARSE_TIME_VRP_H */
\r