]> git.notmuchmail.org Git - notmuch/commitdiff
add property: query prefix to search for specific properties
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 8 Jul 2016 09:15:36 +0000 (11:15 +0200)
committerDavid Bremner <david@tethera.net>
Wed, 21 Sep 2016 21:14:25 +0000 (18:14 -0300)
We want to be able to query the properties directly, like:

   notmuch count property:foo=bar

which should return a count of messages where the property with key
"foo" has value equal to "bar".

doc/man7/notmuch-search-terms.rst
lib/database.cc
test/T610-message-property.sh

index 075f88c8fc6ede178f3561b77a2306553c3a26f7..de93d7332472c97aae460749ecd23eb4c2fb9eed 100644 (file)
@@ -58,6 +58,8 @@ indicate user-supplied values):
 
 -  query:<name>
 
+-  property:<key>=<value>
+
 The **from:** prefix is used to match the name or address of the sender
 of an email message.
 
@@ -139,6 +141,11 @@ queries added with **notmuch-config(1)**. Named queries are only
 available if notmuch is built with **Xapian Field Processors** (see
 below).
 
+The **property:** prefix searches for messages with a particular
+<key>=<value> property pair. Properties are used internally by notmuch
+(and extensions) to add metadata to messages. A given key can be
+present on a given message with several different values.
+
 Operators
 ---------
 
@@ -217,7 +224,7 @@ exact matches like "tag:inbox"  or **probabilistic**, supporting a more flexible
 
 
 Boolean
-   **tag:**, **id:**, **thread:**, **folder:**, **path:**
+   **tag:**, **id:**, **thread:**, **folder:**, **path:**, **property:**
 Probabilistic
    **from:**, **to:**, **subject:**, **attachment:**, **mimetype:**
 
index 33e22d86eae541668b6a896d1ae11fbde732dec0..392e8b2869842130e1372b52d5d9329d0151577e 100644 (file)
@@ -97,6 +97,9 @@ typedef struct {
  *                     STRING is the name of a file within that
  *                     directory for this mail message.
  *
+ *      property:       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
@@ -251,7 +254,6 @@ static prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
     { "directory",             "XDIRECTORY" },
     { "file-direntry",         "XFDIRENTRY" },
     { "directory-direntry",    "XDDIRENTRY" },
-    { "property",               "XPROPERTY"  },
 };
 
 static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
@@ -260,6 +262,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
     { "is",                    "K" },
     { "id",                    "Q" },
     { "path",                  "P" },
+    { "property",              "XPROPERTY" },
     /*
      * Unconditionally add ':' to reduce potential ambiguity with
      * overlapping prefixes and/or terms that start with capital
index c92b99ba32981d19a3e038b291d9f0c8721240f1..65ff19dc17d9401b38611986420794d8537c52d8 100755 (executable)
@@ -237,4 +237,15 @@ notmuch restore < BEFORE2
 notmuch dump | grep '^#=' > OUTPUT
 test_expect_equal_file PROPERTIES OUTPUT
 
+test_begin_subtest "test 'property:' queries: empty"
+notmuch search property:testkey1=charles > OUTPUT
+test_expect_equal_file /dev/null OUTPUT
+
+test_begin_subtest "test 'property:' queries: single message"
+notmuch search --output=messages property:testkey1=alice > OUTPUT
+cat <<EOF >EXPECTED
+id:4EFC743A.3060609@april.org
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done