Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f6 / de75221800ccafcb2dca7895081ac78931481e
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 4B9F5431FBF\r
6         for <notmuch@notmuchmail.org>; Fri,  3 Aug 2012 14:52:14 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id ZoCsBMB4qkdL for <notmuch@notmuchmail.org>;\r
17         Fri,  3 Aug 2012 14:52:12 -0700 (PDT)\r
18 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
19         [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id EB6A2431FAF\r
22         for <notmuch@notmuchmail.org>; Fri,  3 Aug 2012 14:52:11 -0700 (PDT)\r
23 Received: by mail-lpp01m010-f53.google.com with SMTP id u2so681800lag.26\r
24         for <notmuch@notmuchmail.org>; Fri, 03 Aug 2012 14:52:11 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
28         :in-reply-to:references:x-gm-message-state;\r
29         bh=5nGt/GCFCz+Z9K/fzI71uTv8CCG3DMpXI4tw+r3GGxw=;\r
30         b=m0GIZAWEPylSdPcLNdmA1psvZfLHzt4Cn1eW1UxeLYoN2UPLDVQLDb105u+DSpW9MY\r
31         PXimxvkj789mj1L97yyhlu/iuBl6Bhe+Yaj35ZatLYl7nF5Dk4GYnheebVMKyIhOaK4T\r
32         hR30f8yK8xoGL8GoSsWLfQo2MT+uS+7ja8hvzSjd0rX3VpXf4hbDXM4fVeIG/IQbJi+B\r
33         LqN4Z7tDVNOgkf9rgKd6D/YJ35zej95U+dSFgroK3EbCrWJbI1+Q6wM41B1oI39NmYVC\r
34         5dldEbp3pNI+n8ApHSq9jIowWSXF5u3+PzQgs6r2fz6+hFB0i4cFqoR0VQ5j/ZYwTtGa\r
35         UGDw==\r
36 Received: by 10.112.98.70 with SMTP id eg6mr1261325lbb.62.1344030731546;\r
37         Fri, 03 Aug 2012 14:52:11 -0700 (PDT)\r
38 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
39         [80.223.81.27])\r
40         by mx.google.com with ESMTPS id fd1sm2256327lbb.7.2012.08.03.14.52.09\r
41         (version=SSLv3 cipher=OTHER); Fri, 03 Aug 2012 14:52:10 -0700 (PDT)\r
42 From: Jani Nikula <jani@nikula.org>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 5/7] lib: add date range query support\r
45 Date: Sat,  4 Aug 2012 00:51:50 +0300\r
46 Message-Id:\r
47  <8aeefad3bb883a9fba5a9db4619b031cd7f290a3.1344028781.git.jani@nikula.org>\r
48 X-Mailer: git-send-email 1.7.9.5\r
49 In-Reply-To: <cover.1344028781.git.jani@nikula.org>\r
50 References: <cover.1344028781.git.jani@nikula.org>\r
51 In-Reply-To: <cover.1344028781.git.jani@nikula.org>\r
52 References: <cover.1344028781.git.jani@nikula.org>\r
53 X-Gm-Message-State:\r
54  ALoCoQkiO8ePGH7LERqgybAkBJjgX3l7C0PEfYm/UaRbMNBknWVPGyRyTO91ysiIeXs9g5BW9+U/\r
55 X-BeenThere: notmuch@notmuchmail.org\r
56 X-Mailman-Version: 2.1.13\r
57 Precedence: list\r
58 List-Id: "Use and development of the notmuch mail system."\r
59         <notmuch.notmuchmail.org>\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
63 List-Post: <mailto:notmuch@notmuchmail.org>\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
67 X-List-Received-Date: Fri, 03 Aug 2012 21:52:14 -0000\r
68 \r
69 Add a custom value range processor to enable date and time searches of\r
70 the form date:since..until, where "since" and "until" are expressions\r
71 understood by the previously added date/time parser, to restrict the\r
72 results to messages within a particular time range (based on the Date:\r
73 header).\r
74 \r
75 If "since" or "until" describes date/time at an accuracy of days or\r
76 less, the values are rounded according to the accuracy, towards past\r
77 for "since" and towards future for "until". For example,\r
78 date:november..yesterday would match from the beginning of November\r
79 until the end of yesterday. Expressions such as date:today..today\r
80 means since the beginning of today until the end of today.\r
81 \r
82 Open-ended ranges are supported (since Xapian 1.2.1), i.e. you can\r
83 specify date:..until or date:since.. to not limit the start or end\r
84 date, respectively.\r
85 \r
86 CAVEATS:\r
87 \r
88 Xapian does not support spaces in range expressions. You can replace\r
89 the spaces with '_', or (in most cases) '-', or (in some cases) leave\r
90 the spaces out altogether.\r
91 \r
92 Entering date:expr without ".." (for example date:yesterday) will not\r
93 work as you might expect. You can achieve the expected result by\r
94 duplicating the expr both sides of ".." (for example\r
95 date:yesterday..yesterday).\r
96 \r
97 Open-ended ranges won't work with pre-1.2.1 Xapian, but they don't\r
98 produce an error either.\r
99 \r
100 Signed-off-by: Jani Nikula <jani@nikula.org>\r
101 ---\r
102  lib/Makefile.local     |    1 +\r
103  lib/database-private.h |    1 +\r
104  lib/database.cc        |    5 +++++\r
105  lib/parse-time-vrp.cc  |   40 ++++++++++++++++++++++++++++++++++++++++\r
106  lib/parse-time-vrp.h   |   19 +++++++++++++++++++\r
107  5 files changed, 66 insertions(+)\r
108  create mode 100644 lib/parse-time-vrp.cc\r
109  create mode 100644 lib/parse-time-vrp.h\r
110 \r
111 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
112 index e29c3a2..e872ea1 100644\r
113 --- a/lib/Makefile.local\r
114 +++ b/lib/Makefile.local\r
115 @@ -59,6 +59,7 @@ libnotmuch_c_srcs =           \\r
116  \r
117  libnotmuch_cxx_srcs =          \\r
118         $(dir)/database.cc      \\r
119 +       $(dir)/parse-time-vrp.cc        \\r
120         $(dir)/directory.cc     \\r
121         $(dir)/index.cc         \\r
122         $(dir)/message.cc       \\r
123 diff --git a/lib/database-private.h b/lib/database-private.h\r
124 index 88532d5..d3e65fd 100644\r
125 --- a/lib/database-private.h\r
126 +++ b/lib/database-private.h\r
127 @@ -52,6 +52,7 @@ struct _notmuch_database {\r
128      Xapian::QueryParser *query_parser;\r
129      Xapian::TermGenerator *term_gen;\r
130      Xapian::ValueRangeProcessor *value_range_processor;\r
131 +    Xapian::ValueRangeProcessor *date_range_processor;\r
132  };\r
133  \r
134  /* Return the list of terms from the given iterator matching a prefix.\r
135 diff --git a/lib/database.cc b/lib/database.cc\r
136 index 761dc1a..4df3217 100644\r
137 --- a/lib/database.cc\r
138 +++ b/lib/database.cc\r
139 @@ -19,6 +19,7 @@\r
140   */\r
141  \r
142  #include "database-private.h"\r
143 +#include "parse-time-vrp.h"\r
144  \r
145  #include <iostream>\r
146  \r
147 @@ -710,12 +711,14 @@ notmuch_database_open (const char *path,\r
148         notmuch->term_gen = new Xapian::TermGenerator;\r
149         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
150         notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
151 +       notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
152  \r
153         notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
154         notmuch->query_parser->set_database (*notmuch->xapian_db);\r
155         notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));\r
156         notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);\r
157         notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);\r
158 +       notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);\r
159  \r
160         for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
161             prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
162 @@ -778,6 +781,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
163      notmuch->xapian_db = NULL;\r
164      delete notmuch->value_range_processor;\r
165      notmuch->value_range_processor = NULL;\r
166 +    delete notmuch->date_range_processor;\r
167 +    notmuch->date_range_processor = NULL;\r
168  }\r
169  \r
170  void\r
171 diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
172 new file mode 100644\r
173 index 0000000..148c117\r
174 --- /dev/null\r
175 +++ b/lib/parse-time-vrp.cc\r
176 @@ -0,0 +1,40 @@\r
177 +\r
178 +#include "database-private.h"\r
179 +#include "parse-time-vrp.h"\r
180 +#include "parse-time-string.h"\r
181 +\r
182 +#define PREFIX "date:"\r
183 +\r
184 +/* See *ValueRangeProcessor in xapian-core/api/valuerangeproc.cc */\r
185 +Xapian::valueno\r
186 +ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
187 +{\r
188 +    time_t t, now;\r
189 +\r
190 +    /* Require date: prefix in start of the range... */\r
191 +    if (STRNCMP_LITERAL (begin.c_str (), PREFIX))\r
192 +       return Xapian::BAD_VALUENO;\r
193 +\r
194 +    /* ...and remove it. */\r
195 +    begin.erase (0, sizeof (PREFIX) - 1);\r
196 +\r
197 +    /* Use the same 'now' for begin and end. */\r
198 +    if (time (&now) == (time_t) -1)\r
199 +       return Xapian::BAD_VALUENO;\r
200 +\r
201 +    if (!begin.empty ()) {\r
202 +       if (parse_time_string (begin.c_str (), &t, &now, PARSE_TIME_ROUND_DOWN))\r
203 +           return Xapian::BAD_VALUENO;\r
204 +\r
205 +       begin.assign (Xapian::sortable_serialise ((double) t));\r
206 +    }\r
207 +\r
208 +    if (!end.empty ()) {\r
209 +       if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP))\r
210 +           return Xapian::BAD_VALUENO;\r
211 +\r
212 +       end.assign (Xapian::sortable_serialise ((double) t));\r
213 +    }\r
214 +\r
215 +    return valno;\r
216 +}\r
217 diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h\r
218 new file mode 100644\r
219 index 0000000..526c217\r
220 --- /dev/null\r
221 +++ b/lib/parse-time-vrp.h\r
222 @@ -0,0 +1,19 @@\r
223 +\r
224 +#ifndef NOTMUCH_PARSE_TIME_VRP_H\r
225 +#define NOTMUCH_PARSE_TIME_VRP_H\r
226 +\r
227 +#include <xapian.h>\r
228 +\r
229 +/* see *ValueRangeProcessor in xapian-core/include/xapian/queryparser.h */\r
230 +class ParseTimeValueRangeProcessor : public Xapian::ValueRangeProcessor {\r
231 +protected:\r
232 +    Xapian::valueno valno;\r
233 +\r
234 +public:\r
235 +    ParseTimeValueRangeProcessor (Xapian::valueno slot_)\r
236 +       : valno(slot_) { }\r
237 +\r
238 +    Xapian::valueno operator() (std::string &begin, std::string &end);\r
239 +};\r
240 +\r
241 +#endif /* NOTMUCH_PARSE_TIME_VRP_H */\r
242 -- \r
243 1.7.9.5\r
244 \r