1 Return-Path: <bremner@tethera.net>
\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 arlo.cworth.org (Postfix) with ESMTP id CF1906DE00BD
\r
6 for <notmuch@notmuchmail.org>; Sat, 19 Mar 2016 18:38:47 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.03 tagged_above=-999 required=5 tests=[AWL=-0.019,
\r
12 SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id fg26qZN8khNY for <notmuch@notmuchmail.org>;
\r
16 Sat, 19 Mar 2016 18:38:38 -0700 (PDT)
\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id 0F2996DE0032
\r
19 for <notmuch@notmuchmail.org>; Sat, 19 Mar 2016 18:38:38 -0700 (PDT)
\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
21 (envelope-from <bremner@tethera.net>)
\r
22 id 1ahSKm-0001W0-3W; Sat, 19 Mar 2016 21:39:12 -0400
\r
23 Received: (nullmailer pid 17760 invoked by uid 1000);
\r
24 Sun, 20 Mar 2016 01:38:32 -0000
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [PATCH 3/3] lib: optionally support single argument date: queries
\r
28 Date: Sat, 19 Mar 2016 22:38:24 -0300
\r
29 Message-Id: <1458437904-17677-4-git-send-email-david@tethera.net>
\r
30 X-Mailer: git-send-email 2.7.0
\r
31 In-Reply-To: <1458437904-17677-1-git-send-email-david@tethera.net>
\r
32 References: <1458437904-17677-1-git-send-email-david@tethera.net>
\r
34 Content-Type: text/plain; charset=UTF-8
\r
35 Content-Transfer-Encoding: 8bit
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.20
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Sun, 20 Mar 2016 01:38:47 -0000
\r
50 This relies on the FieldProcessor API, which is only present in xapian
\r
53 lib/database-private.h | 4 ++++
\r
54 lib/database.cc | 6 ++++++
\r
55 lib/parse-time-vrp.cc | 21 +++++++++++++++++++++
\r
56 lib/parse-time-vrp.h | 5 +++++
\r
57 test/T500-search-date.sh | 6 ++++++
\r
58 5 files changed, 42 insertions(+)
\r
60 diff --git a/lib/database-private.h b/lib/database-private.h
\r
61 index 3fb10f7..fb2c8ec 100644
\r
62 --- a/lib/database-private.h
\r
63 +++ b/lib/database-private.h
\r
64 @@ -144,6 +144,7 @@ operator&=(_notmuch_features &a, _notmuch_features b)
\r
68 +class DateFieldProcessor;
\r
69 struct _notmuch_database {
\r
70 notmuch_bool_t exception_reported;
\r
72 @@ -176,6 +177,9 @@ struct _notmuch_database {
\r
73 Xapian::TermGenerator *term_gen;
\r
74 Xapian::ValueRangeProcessor *value_range_processor;
\r
75 Xapian::ValueRangeProcessor *date_range_processor;
\r
76 +#if HAVE_XAPIAN_FIELD_PROCESSOR
\r
77 + DateFieldProcessor *date_field_processor;
\r
79 Xapian::ValueRangeProcessor *last_mod_range_processor;
\r
82 diff --git a/lib/database.cc b/lib/database.cc
\r
83 index 3b342f1..0e3c90c 100644
\r
84 --- a/lib/database.cc
\r
85 +++ b/lib/database.cc
\r
86 @@ -1000,6 +1000,12 @@ notmuch_database_open_verbose (const char *path,
\r
87 notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
\r
88 notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
\r
89 notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
\r
90 +#if HAVE_XAPIAN_FIELD_PROCESSOR
\r
91 + /* This currently relies on the query parser to pass anything
\r
92 + * with a .. to the range processor */
\r
93 + notmuch->date_field_processor = new DateFieldProcessor();
\r
94 + notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor);
\r
96 notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");
\r
98 notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
\r
99 diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc
\r
100 index 03804cf..b15b77c 100644
\r
101 --- a/lib/parse-time-vrp.cc
\r
102 +++ b/lib/parse-time-vrp.cc
\r
103 @@ -64,3 +64,24 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)
\r
108 +#if HAVE_XAPIAN_FIELD_PROCESSOR
\r
109 +/* XXX TODO: is throwing an exception the right thing to do here? */
\r
110 +Xapian::Query DateFieldProcessor::operator()(const std::string & str) {
\r
111 + time_t from, to, now;
\r
113 + /* Use the same 'now' for begin and end. */
\r
114 + if (time (&now) == (time_t) -1)
\r
115 + throw Xapian::QueryParserError("Unable to get current time");
\r
117 + if (parse_time_string (str.c_str (), &from, &now, PARSE_TIME_ROUND_DOWN))
\r
118 + throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");
\r
120 + if (parse_time_string (str.c_str (), &to, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))
\r
121 + throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");
\r
123 + return Xapian::Query(Xapian::Query::OP_AND,
\r
124 + Xapian::Query(Xapian::Query::OP_VALUE_GE, 0, Xapian::sortable_serialise ((double) from)),
\r
125 + Xapian::Query(Xapian::Query::OP_VALUE_LE, 0, Xapian::sortable_serialise ((double) to)));
\r
128 diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h
\r
129 index 094c4f8..3bd12bf 100644
\r
130 --- a/lib/parse-time-vrp.h
\r
131 +++ b/lib/parse-time-vrp.h
\r
132 @@ -37,4 +37,9 @@ public:
\r
133 Xapian::valueno operator() (std::string &begin, std::string &end);
\r
136 +#if HAVE_XAPIAN_FIELD_PROCESSOR
\r
137 +class DateFieldProcessor : public Xapian::FieldProcessor {
\r
138 + Xapian::Query operator()(const std::string & str);
\r
141 #endif /* NOTMUCH_PARSE_TIME_VRP_H */
\r
142 diff --git a/test/T500-search-date.sh b/test/T500-search-date.sh
\r
143 index f5cea42..198a2e6 100755
\r
144 --- a/test/T500-search-date.sh
\r
145 +++ b/test/T500-search-date.sh
\r
146 @@ -12,6 +12,12 @@ test_begin_subtest "Absolute date range with 'same' operator"
\r
147 output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize)
\r
148 test_expect_equal "$output" "thread:XXX 2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)"
\r
150 +if [ "${NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR}" = "1" ]; then
\r
151 + test_begin_subtest "Absolute date field"
\r
152 + output=$(notmuch search date:2010-12-16 | notmuch_search_sanitize)
\r
153 + test_expect_equal "$output" "thread:XXX 2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)"
\r
156 test_begin_subtest "Absolute time range with TZ"
\r
157 notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT
\r
158 cat <<EOF >EXPECTED
\r