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