Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / d9 / 8c03bfe1234c6b87c4473854618be521e88935
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 50923429E33\r
6         for <notmuch@notmuchmail.org>; Wed, 10 Aug 2011 03:23:48 -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 V-mAZY+K0r6Q for <notmuch@notmuchmail.org>;\r
17         Wed, 10 Aug 2011 03:23:46 -0700 (PDT)\r
18 Received: from mail-qw0-f53.google.com (mail-qw0-f53.google.com\r
19         [209.85.216.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 D22CB431FB6\r
22         for <notmuch@notmuchmail.org>; Wed, 10 Aug 2011 03:23:44 -0700 (PDT)\r
23 Received: by mail-qw0-f53.google.com with SMTP id 7so539114qwb.26\r
24         for <notmuch@notmuchmail.org>; Wed, 10 Aug 2011 03:22:25 -0700 (PDT)\r
25 Received: by 10.229.131.159 with SMTP id x31mr6093700qcs.193.1312971745023;\r
26         Wed, 10 Aug 2011 03:22:25 -0700 (PDT)\r
27 Received: from localhost (nikula.org [92.243.24.172])\r
28         by mx.google.com with ESMTPS id o4sm717915qct.1.2011.08.10.03.22.23\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Wed, 10 Aug 2011 03:22:24 -0700 (PDT)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [RFC PATCH 3/3] lib: add gnulib get_date() based date range search\r
34 Date: Wed, 10 Aug 2011 10:22:07 +0000\r
35 Message-Id:\r
36  <8ed532337c898d9075bbce00a7b2aaf9f13283b0.1312964528.git.jani@nikula.org>\r
37 X-Mailer: git-send-email 1.7.1\r
38 In-Reply-To: <cover.1312964528.git.jani@nikula.org>\r
39 References: <cover.1312964528.git.jani@nikula.org>\r
40 In-Reply-To: <cover.1312964528.git.jani@nikula.org>\r
41 References: <cover.1312964528.git.jani@nikula.org>\r
42 Cc: amdragon@mit.edu\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Wed, 10 Aug 2011 10:23:48 -0000\r
56 \r
57 Add a custom value range processor to handle "date:" using get_date() from\r
58 gnulib. This enables date (and time) searches of the form\r
59 date:since..until, where "since" and "until" are expressions understood by\r
60 get_date(), compatible with most GNU programs. For the date input formats,\r
61 see the GNU coreutils manual:\r
62 http://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html\r
63 \r
64 Open-ended ranges are supported (since Xapian 1.2.1), i.e. you can specify\r
65 date:..until or date:since.. to not limit the start or end date,\r
66 respectively.\r
67 \r
68 Note: The get_date() function has been renamed to parse_datetime() in\r
69 recent gnulib.\r
70 \r
71 EXAMPLES:\r
72 \r
73 date:2-weeks-ago..\r
74 date:today00:00:00..\r
75 date:yesterday00:00:00..today00:00:00\r
76 date:07/14/2011..2011-07-15\r
77 \r
78 BUGS/CAVEATS:\r
79 \r
80 At the moment it seems search phrases with spaces in them are not supported\r
81 in notmuch. For date: this means you can't specify a date with an\r
82 expression with spaces in it. In many (but apparently not all) cases you\r
83 can work around this by replacing spaces with '-' or simply leaving out\r
84 whitespace. For example, date:2-days-ago..yesterday00:00:00.\r
85 \r
86 For the purpose of searching mail, the get_date() implementation has some\r
87 surprising interpretations. For example:\r
88 \r
89 * Any date specification without time, such as date:yesterday.. or\r
90   date:2011-08-10.., means that day at the same time as now (instead of\r
91   00:00:00).\r
92 \r
93 * As a consequence, ranges such as date:yesterday..yesterday match just the\r
94   messages at the same time as now, to the second. The date parser should\r
95   optimally make different kind of interpretations depending on whether\r
96   parsing "since" or "until". For example, date:today..today should cover\r
97   the whole day from beginning to end, date:today00:00:00..today23:59:59.\r
98 \r
99 * date:monday.. means date:next-monday.. (rather than date:last-monday..)\r
100 \r
101 * date:this-week.. really means date:now.. (you probably want\r
102   date:1-week-ago-next-monday00:00:00.. or similar).\r
103 \r
104 However, there is value in being compatible with GNU programs, and the\r
105 input formats have been rather well documented. It would be more surprising\r
106 to deviate from that, and it would also take some effort to do so,\r
107 including testing.\r
108 ---\r
109  lib/Makefile.local     |    1 +\r
110  lib/database-private.h |    1 +\r
111  lib/database.cc        |    4 ++++\r
112  lib/getdate-proc.cc    |   32 ++++++++++++++++++++++++++++++++\r
113  lib/getdate-proc.h     |   21 +++++++++++++++++++++\r
114  5 files changed, 59 insertions(+), 0 deletions(-)\r
115  create mode 100644 lib/getdate-proc.cc\r
116  create mode 100644 lib/getdate-proc.h\r
117 \r
118 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
119 index a1c234f..b722343 100644\r
120 --- a/lib/Makefile.local\r
121 +++ b/lib/Makefile.local\r
122 @@ -63,6 +63,7 @@ libnotmuch_c_srcs =           \\r
123  \r
124  libnotmuch_cxx_srcs =          \\r
125         $(dir)/database.cc      \\r
126 +       $(dir)/getdate-proc.cc  \\r
127         $(dir)/directory.cc     \\r
128         $(dir)/index.cc         \\r
129         $(dir)/message.cc       \\r
130 diff --git a/lib/database-private.h b/lib/database-private.h\r
131 index f705009..d83ae3b 100644\r
132 --- a/lib/database-private.h\r
133 +++ b/lib/database-private.h\r
134 @@ -51,6 +51,7 @@ struct _notmuch_database {\r
135      Xapian::QueryParser *query_parser;\r
136      Xapian::TermGenerator *term_gen;\r
137      Xapian::ValueRangeProcessor *value_range_processor;\r
138 +    Xapian::ValueRangeProcessor *getdate_proc;\r
139  };\r
140  \r
141  /* Return the list of terms from the given iterator matching a prefix.\r
142 diff --git a/lib/database.cc b/lib/database.cc\r
143 index 9c2f4ec..b1a0732 100644\r
144 --- a/lib/database.cc\r
145 +++ b/lib/database.cc\r
146 @@ -19,6 +19,7 @@\r
147   */\r
148  \r
149  #include "database-private.h"\r
150 +#include "getdate-proc.h"\r
151  \r
152  #include <iostream>\r
153  \r
154 @@ -667,12 +668,14 @@ notmuch_database_open (const char *path,\r
155         notmuch->term_gen = new Xapian::TermGenerator;\r
156         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
157         notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
158 +       notmuch->getdate_proc = new GetDateValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP, "date:", true);\r
159  \r
160         notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
161         notmuch->query_parser->set_database (*notmuch->xapian_db);\r
162         notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));\r
163         notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);\r
164         notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);\r
165 +       notmuch->query_parser->add_valuerangeprocessor (notmuch->getdate_proc);\r
166  \r
167         for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
168             prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
169 @@ -716,6 +719,7 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
170      delete notmuch->query_parser;\r
171      delete notmuch->xapian_db;\r
172      delete notmuch->value_range_processor;\r
173 +    delete notmuch->getdate_proc;\r
174      talloc_free (notmuch);\r
175  }\r
176  \r
177 diff --git a/lib/getdate-proc.cc b/lib/getdate-proc.cc\r
178 new file mode 100644\r
179 index 0000000..c384e5a\r
180 --- /dev/null\r
181 +++ b/lib/getdate-proc.cc\r
182 @@ -0,0 +1,32 @@\r
183 +\r
184 +#include "database-private.h"\r
185 +#include "getdate-proc.h"\r
186 +#include "getdate.h"\r
187 +\r
188 +/* see *ValueRangeProcessor in xapian-core/api/valuerangeproc.cc */\r
189 +Xapian::valueno\r
190 +GetDateValueRangeProcessor::operator()(std::string &begin, std::string &end)\r
191 +{\r
192 +    struct timespec result, now;\r
193 +\r
194 +    if (Xapian::StringValueRangeProcessor::operator()(begin, end) == Xapian::BAD_VALUENO)\r
195 +       return Xapian::BAD_VALUENO;\r
196 +\r
197 +    clock_gettime(CLOCK_REALTIME, &now);\r
198 +\r
199 +    if (!begin.empty()) {\r
200 +       if (!get_date(&result, begin.c_str(), &now) || result.tv_sec == -1)\r
201 +           return Xapian::BAD_VALUENO;\r
202 +\r
203 +       begin.assign(Xapian::sortable_serialise((double)result.tv_sec));\r
204 +    }\r
205 +\r
206 +    if (!end.empty()) {\r
207 +       if (!get_date(&result, end.c_str(), &now) || result.tv_sec == -1)\r
208 +           return Xapian::BAD_VALUENO;\r
209 +\r
210 +       end.assign(Xapian::sortable_serialise((double)result.tv_sec));\r
211 +    }\r
212 +\r
213 +    return valno;\r
214 +}\r
215 diff --git a/lib/getdate-proc.h b/lib/getdate-proc.h\r
216 new file mode 100644\r
217 index 0000000..706fc0a\r
218 --- /dev/null\r
219 +++ b/lib/getdate-proc.h\r
220 @@ -0,0 +1,21 @@\r
221 +\r
222 +#ifndef NOTMUCH_GETDATE_PROC_H\r
223 +#define NOTMUCH_GETDATE_PROC_H\r
224 +\r
225 +#include <xapian.h>\r
226 +\r
227 +/* see *ValueRangeProcessor in xapian-core/include/xapian/queryparser.h */\r
228 +class GetDateValueRangeProcessor : public Xapian::StringValueRangeProcessor {\r
229 +public:\r
230 +       GetDateValueRangeProcessor(Xapian::valueno slot_)\r
231 +               : StringValueRangeProcessor(slot_) { }\r
232 +\r
233 +       GetDateValueRangeProcessor(Xapian::valueno slot_,\r
234 +                                  const std::string &str_,\r
235 +                                  bool prefix_ = true)\r
236 +               : StringValueRangeProcessor(slot_, str_, prefix_) { }\r
237 +\r
238 +       Xapian::valueno operator()(std::string &begin, std::string &end);\r
239 +};\r
240 +\r
241 +#endif /* NOTMUCH_GETDATE_PROC_H */\r
242 -- \r
243 1.7.1\r
244 \r