Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 04 / 9366409965e2aa18b93a4c5c2e96b815281f90
1 Return-Path: <dkg@fifthhorseman.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 00B496DE0A4B\r
6  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 03:14:11 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.038\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.038 tagged_above=-999 required=5 tests=[AWL=0.038]\r
12  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 fgf4MI_KJlNz for <notmuch@notmuchmail.org>;\r
16  Fri,  8 Jul 2016 03:14:03 -0700 (PDT)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 1632C6DE091B\r
19  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 03:13:14 -0700 (PDT)\r
20 Received: from fifthhorseman.net (unknown [88.128.80.54])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 33AE7F98B\r
22  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 06:13:13 -0400 (EDT)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id A10D720A8B; Fri,  8 Jul 2016 11:15:36 +0200 (CEST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH] add has: query prefix to search for specific properties\r
28 Date: Fri,  8 Jul 2016 11:15:36 +0200\r
29 Message-Id: <1467969336-7605-1-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.8.1\r
31 In-Reply-To: <1465779955-5539-9-git-send-email-david@tethera.net>\r
32 References: <1465779955-5539-9-git-send-email-david@tethera.net>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.20\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37  <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
39  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
44  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Fri, 08 Jul 2016 10:14:11 -0000\r
46 \r
47 We want to be able to query the properties directly, like:\r
48 \r
49    notmuch count has:foo=bar\r
50 \r
51 which should return a count of messages where the property with key\r
52 "foo" has value equal to "bar".\r
53 \r
54 This patch could be improved:\r
55 \r
56 If no = sign is present (e.g. "has:foo"), it'd be nice to just match\r
57  on every message that has property "foo", regardless of value.\r
58 \r
59 It would also be good to include some tests.\r
60 ---\r
61  lib/database.cc | 4 ++++\r
62  1 file changed, 4 insertions(+)\r
63 \r
64 This applies atop bermner's "message properties" series, and makes it\r
65 possible to query for messages with specific properties.\r
66 \r
67 diff --git a/lib/database.cc b/lib/database.cc\r
68 index 3a741f0..3bdbd07 100644\r
69 --- a/lib/database.cc\r
70 +++ b/lib/database.cc\r
71 @@ -97,6 +97,9 @@ typedef struct {\r
72   *                     STRING is the name of a file within that\r
73   *                     directory for this mail message.\r
74   *\r
75 + *      has:       Has a property with key=value\r
76 + *                 FIXME: if no = is present, should match on any value\r
77 + *\r
78   *    A mail document also has four values:\r
79   *\r
80   *     TIMESTAMP:      The time_t value corresponding to the message's\r
81 @@ -260,6 +263,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
82      { "is",                    "K" },\r
83      { "id",                    "Q" },\r
84      { "path",                  "P" },\r
85 +    { "has",                   "XPROPERTY" },\r
86      /*\r
87       * Without the ":", since this is a multi-letter prefix, Xapian\r
88       * will add a colon itself if the first letter of the path is\r
89 -- \r
90 2.8.1\r
91 \r