RE: [Spam-verdenking][english 100%] Re: another bug fix release: 0.15.2, in progress.
[notmuch-archives.git] / 18 / 9e1728ee51c56e9dd1f7eb9e7158f84c9bc2a8
1 Return-Path: <jani@nikula.org>\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 D1479431FBC\r
6         for <notmuch@notmuchmail.org>; Sun, 28 Oct 2012 15:39:08 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 yeHPd1hON8rc for <notmuch@notmuchmail.org>;\r
16         Sun, 28 Oct 2012 15:39:08 -0700 (PDT)\r
17 Received: from mail-la0-f53.google.com (mail-la0-f53.google.com\r
18         [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id A29E0431FAF\r
21         for <notmuch@notmuchmail.org>; Sun, 28 Oct 2012 15:39:07 -0700 (PDT)\r
22 Received: by mail-la0-f53.google.com with SMTP id l5so3914390lah.26\r
23         for <notmuch@notmuchmail.org>; Sun, 28 Oct 2012 15:39:06 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=google.com; s=20120113;\r
26         h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
27         :message-id:mime-version:content-type:x-gm-message-state;\r
28         bh=ScbGARoCtCCJH8kzhb6Irqez/Pu58HowWEKT5iQ8kB8=;\r
29         b=PefvjM5xS5Cj9yP6frqaNmN0DH7CX8sTpkgAAg2PyF3YevTS5MxV1ocF55jZ0Q4pMS\r
30         /uamChACfFm6xvX7tCbLzlAsvjq+irioVKbTUBIRU/NkmnSNzKA4Nu66rNLmifhNg6UZ\r
31         M6YbNRDTOz+XpGmh25WT3wrxfNCXq3SXxCF8VxOspqiDYhP/Oj9/XmSliZFtDSZ4jywj\r
32         3Zqa2cm+B2wGUZqULN5MV0k/7v0hANn5jTdBfEnWyjvf+6p1xaVJn0wM3azRT5yPOHJP\r
33         cJWWapUdPusC50Jg7zDffbENn4nCFk/XpR2LA01wgAWrC+FOpUwJXYuifaGKKvOrHxIA\r
34         KaxA==\r
35 Received: by 10.112.38.234 with SMTP id j10mr10886774lbk.80.1351463946143;\r
36         Sun, 28 Oct 2012 15:39:06 -0700 (PDT)\r
37 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
38         [80.223.81.27])\r
39         by mx.google.com with ESMTPS id b8sm2560120lbn.8.2012.10.28.15.39.04\r
40         (version=SSLv3 cipher=OTHER); Sun, 28 Oct 2012 15:39:05 -0700 (PDT)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: Austin Clements <amdragon@MIT.EDU>\r
43 Subject: Re: [PATCH v5 6/9] lib: add date range query support\r
44 In-Reply-To: <20121023045255.GQ14861@mit.edu>\r
45 References: <cover.1350854171.git.jani@nikula.org>\r
46         <f21b8702728457c087478b26700e9448bc16c61d.1350854171.git.jani@nikula.org>\r
47         <20121023045255.GQ14861@mit.edu>\r
48 User-Agent: Notmuch/0.14+46~g272a1f1 (http://notmuchmail.org) Emacs/23.4.1\r
49         (i686-pc-linux-gnu)\r
50 Date: Mon, 29 Oct 2012 00:39:02 +0200\r
51 Message-ID: <87fw4ykyrd.fsf@nikula.org>\r
52 MIME-Version: 1.0\r
53 Content-Type: text/plain; charset=us-ascii\r
54 X-Gm-Message-State:\r
55  ALoCoQnSr8KJpnBqalsJwDBV/FlpKM0eGIIBtz+v9ewruXJx+61/oBqNR14Jtf+rmSugqaFS5lZF\r
56 Cc: notmuch@notmuchmail.org\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Sun, 28 Oct 2012 22:39:09 -0000\r
70 \r
71 On Tue, 23 Oct 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
72 > Quoth Jani Nikula on Oct 22 at 12:22 am:\r
73 >> Add a custom value range processor to enable date and time searches of\r
74 >> the form date:since..until, where "since" and "until" are expressions\r
75 >> understood by the previously added date/time parser, to restrict the\r
76 >> results to messages within a particular time range (based on the Date:\r
77 >> header).\r
78 >> \r
79 >> If "since" or "until" describes date/time at an accuracy of days or\r
80 >> less, the values are rounded according to the accuracy, towards past\r
81 >> for "since" and towards future for "until". For example,\r
82 >> date:november..yesterday would match from the beginning of November\r
83 >> until the end of yesterday. Expressions such as date:today..today\r
84 >> means since the beginning of today until the end of today.\r
85 >> \r
86 >> Open-ended ranges are supported (since Xapian 1.2.1), i.e. you can\r
87 >> specify date:..until or date:since.. to not limit the start or end\r
88 >> date, respectively.\r
89 >> \r
90 >> CAVEATS:\r
91 >> \r
92 >> Xapian does not support spaces in range expressions. You can replace\r
93 >> the spaces with '_', or (in most cases) '-', or (in some cases) leave\r
94 >> the spaces out altogether.\r
95 >> \r
96 >> Entering date:expr without ".." (for example date:yesterday) will not\r
97 >> work as you might expect. You can achieve the expected result by\r
98 >> duplicating the expr both sides of ".." (for example\r
99 >> date:yesterday..yesterday).\r
100 >> \r
101 >> Open-ended ranges won't work with pre-1.2.1 Xapian, but they don't\r
102 >> produce an error either.\r
103 >> \r
104 >> Signed-off-by: Jani Nikula <jani@nikula.org>\r
105 >> ---\r
106 >>  lib/Makefile.local     |    1 +\r
107 >>  lib/database-private.h |    1 +\r
108 >>  lib/database.cc        |    5 +++++\r
109 >>  lib/parse-time-vrp.cc  |   40 ++++++++++++++++++++++++++++++++++++++++\r
110 >>  lib/parse-time-vrp.h   |   19 +++++++++++++++++++\r
111 >>  5 files changed, 66 insertions(+)\r
112 >>  create mode 100644 lib/parse-time-vrp.cc\r
113 >>  create mode 100644 lib/parse-time-vrp.h\r
114 >> \r
115 >> diff --git a/lib/Makefile.local b/lib/Makefile.local\r
116 >> index d1635cf..6c0f42f 100644\r
117 >> --- a/lib/Makefile.local\r
118 >> +++ b/lib/Makefile.local\r
119 >> @@ -58,6 +58,7 @@ libnotmuch_c_srcs =                \\r
120 >>  \r
121 >>  libnotmuch_cxx_srcs =               \\r
122 >>      $(dir)/database.cc      \\r
123 >> +    $(dir)/parse-time-vrp.cc        \\r
124 >>      $(dir)/directory.cc     \\r
125 >>      $(dir)/index.cc         \\r
126 >>      $(dir)/message.cc       \\r
127 >> diff --git a/lib/database-private.h b/lib/database-private.h\r
128 >> index 88532d5..d3e65fd 100644\r
129 >> --- a/lib/database-private.h\r
130 >> +++ b/lib/database-private.h\r
131 >> @@ -52,6 +52,7 @@ struct _notmuch_database {\r
132 >>      Xapian::QueryParser *query_parser;\r
133 >>      Xapian::TermGenerator *term_gen;\r
134 >>      Xapian::ValueRangeProcessor *value_range_processor;\r
135 >> +    Xapian::ValueRangeProcessor *date_range_processor;\r
136 >>  };\r
137 >>  \r
138 >>  /* Return the list of terms from the given iterator matching a prefix.\r
139 >> diff --git a/lib/database.cc b/lib/database.cc\r
140 >> index 761dc1a..4df3217 100644\r
141 >> --- a/lib/database.cc\r
142 >> +++ b/lib/database.cc\r
143 >> @@ -19,6 +19,7 @@\r
144 >>   */\r
145 >>  \r
146 >>  #include "database-private.h"\r
147 >> +#include "parse-time-vrp.h"\r
148 >>  \r
149 >>  #include <iostream>\r
150 >>  \r
151 >> @@ -710,12 +711,14 @@ notmuch_database_open (const char *path,\r
152 >>      notmuch->term_gen = new Xapian::TermGenerator;\r
153 >>      notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
154 >>      notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
155 >> +    notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
156 >>  \r
157 >>      notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
158 >>      notmuch->query_parser->set_database (*notmuch->xapian_db);\r
159 >>      notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));\r
160 >>      notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);\r
161 >>      notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);\r
162 >> +    notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);\r
163 >>  \r
164 >>      for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
165 >>          prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
166 >> @@ -778,6 +781,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
167 >>      notmuch->xapian_db = NULL;\r
168 >>      delete notmuch->value_range_processor;\r
169 >>      notmuch->value_range_processor = NULL;\r
170 >> +    delete notmuch->date_range_processor;\r
171 >> +    notmuch->date_range_processor = NULL;\r
172 >>  }\r
173 >>  \r
174 >>  void\r
175 >> diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
176 >> new file mode 100644\r
177 >> index 0000000..7e4eca4\r
178 >> --- /dev/null\r
179 >> +++ b/lib/parse-time-vrp.cc\r
180 >> @@ -0,0 +1,40 @@\r
181 >\r
182 > Should this file have the usual preamble?\r
183 \r
184 Probably, yes.\r
185 \r
186 >> +\r
187 >> +#include "database-private.h"\r
188 >> +#include "parse-time-vrp.h"\r
189 >> +#include "parse-time-string.h"\r
190 >> +\r
191 >> +#define PREFIX "date:"\r
192 >> +\r
193 >> +/* See *ValueRangeProcessor in xapian-core/api/valuerangeproc.cc */\r
194 >> +Xapian::valueno\r
195 >> +ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
196 >> +{\r
197 >> +    time_t t, now;\r
198 >> +\r
199 >> +    /* Require date: prefix in start of the range... */\r
200 >> +    if (STRNCMP_LITERAL (begin.c_str (), PREFIX))\r
201 >\r
202 > Could be\r
203 >   if (begin.rfind (PREFIX, 0) == string::npos)\r
204 > but that may not be clearer.\r
205 \r
206 Not to me at least; my C++ is rusty.\r
207 \r
208 >> +    return Xapian::BAD_VALUENO;\r
209 >> +\r
210 >> +    /* ...and remove it. */\r
211 >> +    begin.erase (0, sizeof (PREFIX) - 1);\r
212 >> +\r
213 >> +    /* Use the same 'now' for begin and end. */\r
214 >> +    if (time (&now) == (time_t) -1)\r
215 >> +    return Xapian::BAD_VALUENO;\r
216 >> +\r
217 >> +    if (!begin.empty ()) {\r
218 >> +    if (parse_time_string (begin.c_str (), &t, &now, PARSE_TIME_ROUND_DOWN))\r
219 >> +        return Xapian::BAD_VALUENO;\r
220 >> +\r
221 >> +    begin.assign (Xapian::sortable_serialise ((double) t));\r
222 >> +    }\r
223 >> +\r
224 >> +    if (!end.empty ()) {\r
225 >> +    if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))\r
226 >> +        return Xapian::BAD_VALUENO;\r
227 >> +\r
228 >> +    end.assign (Xapian::sortable_serialise ((double) t));\r
229 >> +    }\r
230 >> +\r
231 >> +    return valno;\r
232 >> +}\r
233 >> diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h\r
234 >> new file mode 100644\r
235 >> index 0000000..526c217\r
236 >> --- /dev/null\r
237 >> +++ b/lib/parse-time-vrp.h\r
238 >> @@ -0,0 +1,19 @@\r
239 >\r
240 > Same thing about the preamble.\r
241 >\r
242 >> +\r
243 >> +#ifndef NOTMUCH_PARSE_TIME_VRP_H\r
244 >> +#define NOTMUCH_PARSE_TIME_VRP_H\r
245 >> +\r
246 >> +#include <xapian.h>\r
247 >> +\r
248 >> +/* see *ValueRangeProcessor in xapian-core/include/xapian/queryparser.h */\r
249 >\r
250 > Out of curiosity, why the Xapian source reference?\r
251 > ValueRangeProcessor is documented along the rest of Xapian.\r
252 \r
253 To be honest, I couldn't write this with the documentation alone, and\r
254 Xapian has quite a bit of source code, so I wrote it down for me. I\r
255 figured it does no harm to leave it there.\r
256 \r
257 BR,\r
258 Jani.\r
259 \r
260 >> +class ParseTimeValueRangeProcessor : public Xapian::ValueRangeProcessor {\r
261 >> +protected:\r
262 >> +    Xapian::valueno valno;\r
263 >> +\r
264 >> +public:\r
265 >> +    ParseTimeValueRangeProcessor (Xapian::valueno slot_)\r
266 >> +    : valno(slot_) { }\r
267 >> +\r
268 >> +    Xapian::valueno operator() (std::string &begin, std::string &end);\r
269 >> +};\r
270 >> +\r
271 >> +#endif /* NOTMUCH_PARSE_TIME_VRP_H */\r