Re: [PATCH 6/6] emacs: `notmuch-show-tag-all' sans prefix arg only tags open messages
[notmuch-archives.git] / 0a / 1a7023309ba5ab50f2ec058a47035438827121
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 B28CA431FC2\r
6         for <notmuch@notmuchmail.org>; Sun, 19 Feb 2012 14:56:12 -0800 (PST)\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 vyvV3C-Aj58G for <notmuch@notmuchmail.org>;\r
17         Sun, 19 Feb 2012 14:56:09 -0800 (PST)\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 E3E44431FC4\r
22         for <notmuch@notmuchmail.org>; Sun, 19 Feb 2012 14:56:03 -0800 (PST)\r
23 Received: by mail-lpp01m010-f53.google.com with SMTP id d3so5943891lah.26\r
24         for <notmuch@notmuchmail.org>; Sun, 19 Feb 2012 14:56:03 -0800 (PST)\r
25 Received-SPF: pass (google.com: domain of jani@nikula.org designates\r
26         10.112.9.40 as permitted sender) client-ip=10.112.9.40; \r
27 Authentication-Results: mr.google.com;\r
28         spf=pass (google.com: domain of jani@nikula.org\r
29         designates 10.112.9.40 as permitted sender)\r
30         smtp.mail=jani@nikula.org\r
31 Received: from mr.google.com ([10.112.9.40])\r
32         by 10.112.9.40 with SMTP id w8mr6460826lba.103.1329692163562 (num_hops\r
33         = 1); Sun, 19 Feb 2012 14:56:03 -0800 (PST)\r
34 MIME-Version: 1.0\r
35 Received: by 10.112.9.40 with SMTP id w8mr5364160lba.103.1329692163395;\r
36         Sun, 19 Feb 2012 14:56:03 -0800 (PST)\r
37 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
38         [84.248.80.253])\r
39         by mx.google.com with ESMTPS id os5sm16890205lab.13.2012.02.19.14.56.01\r
40         (version=SSLv3 cipher=OTHER); Sun, 19 Feb 2012 14:56:02 -0800 (PST)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [RFC PATCH 2/2] lib: add date range search\r
44 Date: Mon, 20 Feb 2012 00:55:52 +0200\r
45 Message-Id:\r
46  <c02a53f8e1d6b7d12f17b8b5e578885790a5ea46.1329689945.git.jani@nikula.org>\r
47 X-Mailer: git-send-email 1.7.5.4\r
48 In-Reply-To: <cover.1329689945.git.jani@nikula.org>\r
49 References: <cover.1329689945.git.jani@nikula.org>\r
50 In-Reply-To: <cover.1329689945.git.jani@nikula.org>\r
51 References: <cover.1329689945.git.jani@nikula.org>\r
52 X-Gm-Message-State:\r
53  ALoCoQmuB6fhLoAnO2mhYj8sv+c2RzNeuaYuciZ8N0BGETURxCsUrTg/kjocKBHFJiKmjTNKmaJR\r
54 X-BeenThere: notmuch@notmuchmail.org\r
55 X-Mailman-Version: 2.1.13\r
56 Precedence: list\r
57 List-Id: "Use and development of the notmuch mail system."\r
58         <notmuch.notmuchmail.org>\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
62 List-Post: <mailto:notmuch@notmuchmail.org>\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
66 X-List-Received-Date: Sun, 19 Feb 2012 22:56:12 -0000\r
67 \r
68 Add a custom value range processor to enable date and time searches of\r
69 the form date:since..until, where "since" and "until" are expressions\r
70 understood by parse_time_string().\r
71 \r
72 If "since" or "until" describes date/time at an accuracy of days or\r
73 less, the values are rounded according to the accuracy, towards past\r
74 for "since" and towards future for "until". For example,\r
75 date:november..yesterday would match from the beginning of November\r
76 until the end of yesterday. Expressions such as date:today..today\r
77 means since the beginning of today until the end of today.\r
78 \r
79 Open-ended ranges are supported (since Xapian 1.2.1), i.e. you can\r
80 specify date:..until or date:since.. to not limit the start or end\r
81 date, respectively.\r
82 \r
83 CAVEATS:\r
84 \r
85 Xapian does not support spaces in range expressions. You can replace\r
86 the spaces with '_' or (in most cases) '-' or (in some cases) leave\r
87 the spaces out altogether.\r
88 \r
89 Entering date:expr without ".." (for example date:yesterday) won't\r
90 work. You can achieve the expected result by duplicating the expr both\r
91 sides of ".." (for example date:yesterday..yesterday).\r
92 \r
93 Signed-off-by: Jani Nikula <jani@nikula.org>\r
94 ---\r
95  lib/Makefile.local     |    1 +\r
96  lib/database-private.h |    1 +\r
97  lib/database.cc        |    4 ++++\r
98  lib/getdate-proc.cc    |   34 ++++++++++++++++++++++++++++++++++\r
99  lib/getdate-proc.h     |   21 +++++++++++++++++++++\r
100  5 files changed, 61 insertions(+), 0 deletions(-)\r
101  create mode 100644 lib/getdate-proc.cc\r
102  create mode 100644 lib/getdate-proc.h\r
103 \r
104 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
105 index 803a284..7dd1f7d 100644\r
106 --- a/lib/Makefile.local\r
107 +++ b/lib/Makefile.local\r
108 @@ -59,6 +59,7 @@ libnotmuch_c_srcs =           \\r
109  \r
110  libnotmuch_cxx_srcs =          \\r
111         $(dir)/database.cc      \\r
112 +       $(dir)/getdate-proc.cc  \\r
113         $(dir)/directory.cc     \\r
114         $(dir)/index.cc         \\r
115         $(dir)/message.cc       \\r
116 diff --git a/lib/database-private.h b/lib/database-private.h\r
117 index 88532d5..ba13dc7 100644\r
118 --- a/lib/database-private.h\r
119 +++ b/lib/database-private.h\r
120 @@ -52,6 +52,7 @@ struct _notmuch_database {\r
121      Xapian::QueryParser *query_parser;\r
122      Xapian::TermGenerator *term_gen;\r
123      Xapian::ValueRangeProcessor *value_range_processor;\r
124 +    Xapian::ValueRangeProcessor *getdate_proc;\r
125  };\r
126  \r
127  /* Return the list of terms from the given iterator matching a prefix.\r
128 diff --git a/lib/database.cc b/lib/database.cc\r
129 index c928d02..a3f8adb 100644\r
130 --- a/lib/database.cc\r
131 +++ b/lib/database.cc\r
132 @@ -19,6 +19,7 @@\r
133   */\r
134  \r
135  #include "database-private.h"\r
136 +#include "getdate-proc.h"\r
137  \r
138  #include <iostream>\r
139  \r
140 @@ -682,12 +683,14 @@ notmuch_database_open (const char *path,\r
141         notmuch->term_gen = new Xapian::TermGenerator;\r
142         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
143         notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
144 +       notmuch->getdate_proc = new GetDateValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP, "date:", true);\r
145  \r
146         notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
147         notmuch->query_parser->set_database (*notmuch->xapian_db);\r
148         notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));\r
149         notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);\r
150         notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);\r
151 +       notmuch->query_parser->add_valuerangeprocessor (notmuch->getdate_proc);\r
152  \r
153         for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
154             prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
155 @@ -729,6 +732,7 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
156      delete notmuch->query_parser;\r
157      delete notmuch->xapian_db;\r
158      delete notmuch->value_range_processor;\r
159 +    delete notmuch->getdate_proc;\r
160      talloc_free (notmuch);\r
161  }\r
162  \r
163 diff --git a/lib/getdate-proc.cc b/lib/getdate-proc.cc\r
164 new file mode 100644\r
165 index 0000000..31f8f03\r
166 --- /dev/null\r
167 +++ b/lib/getdate-proc.cc\r
168 @@ -0,0 +1,34 @@\r
169 +\r
170 +#include "database-private.h"\r
171 +#include "getdate-proc.h"\r
172 +#include "parse-time-string.h"\r
173 +\r
174 +/* see *ValueRangeProcessor in xapian-core/api/valuerangeproc.cc */\r
175 +Xapian::valueno\r
176 +GetDateValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
177 +{\r
178 +    time_t t, now;\r
179 +\r
180 +    if (Xapian::StringValueRangeProcessor::operator() (begin, end) == Xapian::BAD_VALUENO)\r
181 +       return Xapian::BAD_VALUENO;\r
182 +\r
183 +    /* use the same 'now' for begin and end */\r
184 +    if (time (&now) == (time_t) -1)\r
185 +       return Xapian::BAD_VALUENO;\r
186 +\r
187 +    if (!begin.empty ()) {\r
188 +       if (parse_time_string (begin.c_str (), &t, &now, PARSE_TIME_ROUND_DOWN))\r
189 +           return Xapian::BAD_VALUENO;\r
190 +\r
191 +       begin.assign (Xapian::sortable_serialise ((double) t));\r
192 +    }\r
193 +\r
194 +    if (!end.empty ()) {\r
195 +       if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP))\r
196 +           return Xapian::BAD_VALUENO;\r
197 +\r
198 +       end.assign (Xapian::sortable_serialise ((double) t));\r
199 +    }\r
200 +\r
201 +    return valno;\r
202 +}\r
203 diff --git a/lib/getdate-proc.h b/lib/getdate-proc.h\r
204 new file mode 100644\r
205 index 0000000..351d06e\r
206 --- /dev/null\r
207 +++ b/lib/getdate-proc.h\r
208 @@ -0,0 +1,21 @@\r
209 +\r
210 +#ifndef NOTMUCH_GETDATE_PROC_H\r
211 +#define NOTMUCH_GETDATE_PROC_H\r
212 +\r
213 +#include <xapian.h>\r
214 +\r
215 +/* see *ValueRangeProcessor in xapian-core/include/xapian/queryparser.h */\r
216 +class GetDateValueRangeProcessor : public Xapian::StringValueRangeProcessor {\r
217 +public:\r
218 +    GetDateValueRangeProcessor (Xapian::valueno slot_)\r
219 +       : StringValueRangeProcessor (slot_) { }\r
220 +\r
221 +    GetDateValueRangeProcessor (Xapian::valueno slot_,\r
222 +                               const std::string &str_,\r
223 +                               bool prefix_ = true)\r
224 +       : StringValueRangeProcessor (slot_, str_, prefix_) { }\r
225 +\r
226 +    Xapian::valueno operator() (std::string &begin, std::string &end);\r
227 +};\r
228 +\r
229 +#endif /* NOTMUCH_GETDATE_PROC_H */\r
230 -- \r
231 1.7.5.4\r
232 \r