From 3b70e42f5a32f68b9a8d4b070af636f8ec115c38 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 15 Aug 2015 14:25:47 +0300 Subject: [PATCH] [PATCH] lib: add support for date:..! to mean date:.. --- 2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a | 163 ++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a diff --git a/2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a b/2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a new file mode 100644 index 000000000..241af1ce4 --- /dev/null +++ b/2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a @@ -0,0 +1,163 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 2CA0B6DE17FD + for ; Sat, 15 Aug 2015 04:25:48 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.248 +X-Spam-Level: +X-Spam-Status: No, score=-0.248 tagged_above=-999 required=5 tests=[AWL=0.472, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id oiJMmBN0Od3U for ; + Sat, 15 Aug 2015 04:25:46 -0700 (PDT) +Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com + [209.85.212.169]) + by arlo.cworth.org (Postfix) with ESMTPS id F08716DE021E + for ; Sat, 15 Aug 2015 04:25:45 -0700 (PDT) +Received: by wibhh20 with SMTP id hh20so42720009wib.0 + for ; Sat, 15 Aug 2015 04:25:44 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to + :references:mime-version:content-type:content-transfer-encoding; + bh=kO1xVViJfzx+unxR58RtuAtdQC/HNZotS0xPe8oCbrc=; + b=YMqq2iM1ijS2g3QZMSUJynAcoveZAJyHuLrmJaOLVo0/LMoArZ3IRPBddu+SzBZAK9 + IsE9e2EEOQ3SRcPrf3q2y/XO7ACPplokwp/sY1PanZZugsOI5Itk0SkxTWGLh+joTw2T + f5F2KORwMtrJf36JXYMfV+klzM+Uy8XT4eGxpPAlXPDTE/l3yz/njxDko1PPLdSJiiN9 + LRpMxDc03OacE3msADtXIo8w4XbvBt+Qpa2JrvMd8uXUVdm4CZgSy/pxv2h+Czc0S3+O + ctf03ZK4YsVVo6JesuCPp/rXTmJHfOBgd97cXGmqyibnitHioWj2Ww7kHU4Jd79GSrzf + n9AA== +X-Gm-Message-State: + ALoCoQm08GaHFou1AT5fOvsMz+ymbYAE9wq2GN1xZyg85fSB8Gf2qKMfw7K7uS0/852e2DdIkbMG +X-Received: by 10.194.117.5 with SMTP id ka5mr8984258wjb.50.1439637944265; + Sat, 15 Aug 2015 04:25:44 -0700 (PDT) +Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi. + [188.238.79.131]) + by smtp.gmail.com with ESMTPSA id gm20sm12517871wjc.17.2015.08.15.04.25.43 + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 15 Aug 2015 04:25:43 -0700 (PDT) +From: Jani Nikula +To: David Bremner , Jani Nikula , + notmuch@notmuchmail.org +Subject: [PATCH] lib: add support for date:..! to mean + date:.. +Date: Sat, 15 Aug 2015 14:25:47 +0300 +Message-Id: <1439637947-12147-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <87k2vegsda.fsf@maritornes.cs.unb.ca> +References: <87k2vegsda.fsf@maritornes.cs.unb.ca> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 15 Aug 2015 11:25:48 -0000 + +It doesn't seem likely we can support simple date: expanding to +date:.. any time soon. (This can be done with a future +version of Xapian, or with a custom query query parser.) In the mean +time, provide shorthand date:..! to mean the same. This is +useful, as the expansion takes place before interpetation, and we can +use, for example, date:yesterday..! to match from beginning of +yesterday to end of yesterday. + +Idea from Mark Walters . +--- + doc/man7/notmuch-search-terms.rst | 12 +++++++----- + lib/parse-time-vrp.cc | 5 +++++ + test/T500-search-date.sh | 4 ++++ + 3 files changed, 16 insertions(+), 5 deletions(-) + +diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst +index 1d27ac1e6de5..3b35a32b7d23 100644 +--- a/doc/man7/notmuch-search-terms.rst ++++ b/doc/man7/notmuch-search-terms.rst +@@ -270,6 +270,13 @@ In this case, is taken as the earliest time it could describe + could describe (the end of yesterday). Similarly, date:january..february + matches from the beginning of January to the end of February. + ++date:..! can be used as a shorthand for date:... The ++expansion takes place before interpretation, and thus, for example, ++date:monday..! matches from the beginning of Monday until the end of ++Monday. (Note that entering date: without "..", for example ++date:yesterday, won't work, as it's not interpreted as a range ++expression at all. Again, use date:yesterday..!) ++ + Currently, we do not support spaces in range expressions. You can + replace the spaces with '\_', or (in most cases) '-', or (in some cases) + leave the spaces out altogether. Examples in this man page use spaces +@@ -280,11 +287,6 @@ to specify date:.. or date:.. to not limit the start or + end time, respectively. Pre-1.2.1 Xapian does not report an error on + open ended ranges, but it does not work as expected either. + +-Entering date:expr without ".." (for example date:yesterday) won't work, +-as it's not interpreted as a range expression at all. You can achieve +-the expected result by duplicating the expr both sides of ".." (for +-example date:yesterday..yesterday). +- + Relative date and time + ---------------------- + +diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc +index 33f07db3410e..03804cf50fa8 100644 +--- a/lib/parse-time-vrp.cc ++++ b/lib/parse-time-vrp.cc +@@ -31,6 +31,7 @@ Xapian::valueno + ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end) + { + time_t t, now; ++ std::string b; + + /* Require date: prefix in start of the range... */ + if (STRNCMP_LITERAL (begin.c_str (), PREFIX)) +@@ -38,6 +39,7 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end) + + /* ...and remove it. */ + begin.erase (0, sizeof (PREFIX) - 1); ++ b = begin; + + /* Use the same 'now' for begin and end. */ + if (time (&now) == (time_t) -1) +@@ -51,6 +53,9 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end) + } + + if (!end.empty ()) { ++ if (end == "!" && ! b.empty ()) ++ end = b; ++ + if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP_INCLUSIVE)) + return Xapian::BAD_VALUENO; + +diff --git a/test/T500-search-date.sh b/test/T500-search-date.sh +index b28496b78e2e..f5cea421d785 100755 +--- a/test/T500-search-date.sh ++++ b/test/T500-search-date.sh +@@ -8,6 +8,10 @@ test_begin_subtest "Absolute date range" + output=$(notmuch search date:2010-12-16..12/16/2010 | notmuch_search_sanitize) + test_expect_equal "$output" "thread:XXX 2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)" + ++test_begin_subtest "Absolute date range with 'same' operator" ++output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize) ++test_expect_equal "$output" "thread:XXX 2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)" ++ + test_begin_subtest "Absolute time range with TZ" + notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT + cat <EXPECTED +-- +2.1.4 + -- 2.26.2