[PATCH] add has: query prefix to search for specific properties

Subject: [PATCH] add has: query prefix to search for specific properties

Date: Fri, 8 Jul 2016 11:15:36 +0200

To: Notmuch Mail

Cc:

From: Daniel Kahn Gillmor


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


Thread: