--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id CF1906DE00BD\r
+ for <notmuch@notmuchmail.org>; Sat, 19 Mar 2016 18:38:47 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.03\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.03 tagged_above=-999 required=5 tests=[AWL=-0.019,\r
+ SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id fg26qZN8khNY for <notmuch@notmuchmail.org>;\r
+ Sat, 19 Mar 2016 18:38:38 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 0F2996DE0032\r
+ for <notmuch@notmuchmail.org>; Sat, 19 Mar 2016 18:38:38 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1ahSKm-0001W0-3W; Sat, 19 Mar 2016 21:39:12 -0400\r
+Received: (nullmailer pid 17760 invoked by uid 1000);\r
+ Sun, 20 Mar 2016 01:38:32 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] lib: optionally support single argument date: queries\r
+Date: Sat, 19 Mar 2016 22:38:24 -0300\r
+Message-Id: <1458437904-17677-4-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.7.0\r
+In-Reply-To: <1458437904-17677-1-git-send-email-david@tethera.net>\r
+References: <1458437904-17677-1-git-send-email-david@tethera.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 20 Mar 2016 01:38:47 -0000\r
+\r
+This relies on the FieldProcessor API, which is only present in xapian\r
+>= 1.3.\r
+---\r
+ lib/database-private.h | 4 ++++\r
+ lib/database.cc | 6 ++++++\r
+ lib/parse-time-vrp.cc | 21 +++++++++++++++++++++\r
+ lib/parse-time-vrp.h | 5 +++++\r
+ test/T500-search-date.sh | 6 ++++++\r
+ 5 files changed, 42 insertions(+)\r
+\r
+diff --git a/lib/database-private.h b/lib/database-private.h\r
+index 3fb10f7..fb2c8ec 100644\r
+--- a/lib/database-private.h\r
++++ b/lib/database-private.h\r
+@@ -144,6 +144,7 @@ operator&=(_notmuch_features &a, _notmuch_features b)\r
+ return a;\r
+ }\r
+ \r
++class DateFieldProcessor;\r
+ struct _notmuch_database {\r
+ notmuch_bool_t exception_reported;\r
+ \r
+@@ -176,6 +177,9 @@ struct _notmuch_database {\r
+ Xapian::TermGenerator *term_gen;\r
+ Xapian::ValueRangeProcessor *value_range_processor;\r
+ Xapian::ValueRangeProcessor *date_range_processor;\r
++#if HAVE_XAPIAN_FIELD_PROCESSOR\r
++ DateFieldProcessor *date_field_processor;\r
++#endif\r
+ Xapian::ValueRangeProcessor *last_mod_range_processor;\r
+ };\r
+ \r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 3b342f1..0e3c90c 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1000,6 +1000,12 @@ notmuch_database_open_verbose (const char *path,\r
+ notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
+ notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
+ notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
++#if HAVE_XAPIAN_FIELD_PROCESSOR\r
++ /* This currently relies on the query parser to pass anything\r
++ * with a .. to the range processor */\r
++ notmuch->date_field_processor = new DateFieldProcessor();\r
++ notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor);\r
++#endif\r
+ notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");\r
+ \r
+ notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
+diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
+index 03804cf..b15b77c 100644\r
+--- a/lib/parse-time-vrp.cc\r
++++ b/lib/parse-time-vrp.cc\r
+@@ -64,3 +64,24 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
+ \r
+ return valno;\r
+ }\r
++\r
++#if HAVE_XAPIAN_FIELD_PROCESSOR\r
++/* XXX TODO: is throwing an exception the right thing to do here? */\r
++Xapian::Query DateFieldProcessor::operator()(const std::string & str) {\r
++ time_t from, to, now;\r
++\r
++ /* Use the same 'now' for begin and end. */\r
++ if (time (&now) == (time_t) -1)\r
++ throw Xapian::QueryParserError("Unable to get current time");\r
++\r
++ if (parse_time_string (str.c_str (), &from, &now, PARSE_TIME_ROUND_DOWN))\r
++ throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");\r
++\r
++ if (parse_time_string (str.c_str (), &to, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))\r
++ throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");\r
++\r
++ return Xapian::Query(Xapian::Query::OP_AND,\r
++ Xapian::Query(Xapian::Query::OP_VALUE_GE, 0, Xapian::sortable_serialise ((double) from)),\r
++ Xapian::Query(Xapian::Query::OP_VALUE_LE, 0, Xapian::sortable_serialise ((double) to)));\r
++}\r
++#endif\r
+diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h\r
+index 094c4f8..3bd12bf 100644\r
+--- a/lib/parse-time-vrp.h\r
++++ b/lib/parse-time-vrp.h\r
+@@ -37,4 +37,9 @@ public:\r
+ Xapian::valueno operator() (std::string &begin, std::string &end);\r
+ };\r
+ \r
++#if HAVE_XAPIAN_FIELD_PROCESSOR\r
++class DateFieldProcessor : public Xapian::FieldProcessor {\r
++ Xapian::Query operator()(const std::string & str);\r
++};\r
++#endif\r
+ #endif /* NOTMUCH_PARSE_TIME_VRP_H */\r
+diff --git a/test/T500-search-date.sh b/test/T500-search-date.sh\r
+index f5cea42..198a2e6 100755\r
+--- a/test/T500-search-date.sh\r
++++ b/test/T500-search-date.sh\r
+@@ -12,6 +12,12 @@ test_begin_subtest "Absolute date range with 'same' operator"\r
+ output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize)\r
+ test_expect_equal "$output" "thread:XXX 2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)"\r
+ \r
++if [ "${NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR}" = "1" ]; then\r
++ test_begin_subtest "Absolute date field"\r
++ output=$(notmuch search date:2010-12-16 | notmuch_search_sanitize)\r
++ test_expect_equal "$output" "thread:XXX 2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)"\r
++fi\r
++\r
+ test_begin_subtest "Absolute time range with TZ"\r
+ notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT\r
+ cat <<EOF >EXPECTED\r
+-- \r
+2.7.0\r
+\r