From: Daniel Kahn Gillmor Date: Fri, 8 Jul 2016 09:15:36 +0000 (+0200) Subject: [PATCH] add has: query prefix to search for specific properties X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=11fb5f50ffa9814e7445d1b08161117eb16a6b69;p=notmuch-archives.git [PATCH] add has: query prefix to search for specific properties --- diff --git a/04/9366409965e2aa18b93a4c5c2e96b815281f90 b/04/9366409965e2aa18b93a4c5c2e96b815281f90 new file mode 100644 index 000000000..16547ee65 --- /dev/null +++ b/04/9366409965e2aa18b93a4c5c2e96b815281f90 @@ -0,0 +1,91 @@ +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 00B496DE0A4B + for ; Fri, 8 Jul 2016 03:14:11 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.038 +X-Spam-Level: +X-Spam-Status: No, score=0.038 tagged_above=-999 required=5 tests=[AWL=0.038] + 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 fgf4MI_KJlNz for ; + Fri, 8 Jul 2016 03:14:03 -0700 (PDT) +Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) + by arlo.cworth.org (Postfix) with ESMTP id 1632C6DE091B + for ; Fri, 8 Jul 2016 03:13:14 -0700 (PDT) +Received: from fifthhorseman.net (unknown [88.128.80.54]) + by che.mayfirst.org (Postfix) with ESMTPSA id 33AE7F98B + for ; Fri, 8 Jul 2016 06:13:13 -0400 (EDT) +Received: by fifthhorseman.net (Postfix, from userid 1000) + id A10D720A8B; Fri, 8 Jul 2016 11:15:36 +0200 (CEST) +From: Daniel Kahn Gillmor +To: Notmuch Mail +Subject: [PATCH] add has: query prefix to search for specific properties +Date: Fri, 8 Jul 2016 11:15:36 +0200 +Message-Id: <1467969336-7605-1-git-send-email-dkg@fifthhorseman.net> +X-Mailer: git-send-email 2.8.1 +In-Reply-To: <1465779955-5539-9-git-send-email-david@tethera.net> +References: <1465779955-5539-9-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +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: Fri, 08 Jul 2016 10:14:11 -0000 + +We want to be able to query the properties directly, like: + + notmuch count has:foo=bar + +which should return a count of messages where the property with key +"foo" has value equal to "bar". + +This patch could be improved: + +If no = sign is present (e.g. "has:foo"), it'd be nice to just match + on every message that has property "foo", regardless of value. + +It would also be good to include some tests. +--- + lib/database.cc | 4 ++++ + 1 file changed, 4 insertions(+) + +This applies atop bermner's "message properties" series, and makes it +possible to query for messages with specific properties. + +diff --git a/lib/database.cc b/lib/database.cc +index 3a741f0..3bdbd07 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -97,6 +97,9 @@ typedef struct { + * STRING is the name of a file within that + * directory for this mail message. + * ++ * has: Has a property with key=value ++ * FIXME: if no = is present, should match on any value ++ * + * A mail document also has four values: + * + * TIMESTAMP: The time_t value corresponding to the message's +@@ -260,6 +263,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = { + { "is", "K" }, + { "id", "Q" }, + { "path", "P" }, ++ { "has", "XPROPERTY" }, + /* + * Without the ":", since this is a multi-letter prefix, Xapian + * will add a colon itself if the first letter of the path is +-- +2.8.1 +