]> git.notmuchmail.org Git - notmuch/commitdiff
lib: setup user headers in query parser
authorDavid Bremner <david@tethera.net>
Sat, 17 Nov 2018 14:08:59 +0000 (10:08 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 25 May 2019 09:56:16 +0000 (06:56 -0300)
These tests will need to be updated if the Xapian
query print/debug format changes.

lib/database.cc
lib/notmuch-private.h
test/T750-user-header.sh

index 1753117f99361b8f1fe25cacd1152dc25694e446..dd1c1c7d8f7848edd0a675234561fc2f3ec95e4b 100644 (file)
@@ -322,6 +322,42 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
        notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
 }
 
        notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
 }
 
+const char *
+_user_prefix (void *ctx, const char* name)
+{
+    return talloc_asprintf(ctx, "XU%s:", name);
+}
+
+static notmuch_status_t
+_setup_user_query_fields (notmuch_database_t *notmuch)
+{
+    notmuch_config_list_t *list;
+    notmuch_status_t status;
+
+    status = notmuch_database_get_config_list (notmuch, CONFIG_HEADER_PREFIX, &list);
+    if (status)
+       return status;
+
+    for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
+
+       prefix_t query_field;
+
+       const char *key = notmuch_config_list_key (list)
+           + sizeof (CONFIG_HEADER_PREFIX) - 1;
+
+       query_field.name = talloc_strdup (notmuch, key);
+       query_field.prefix = _user_prefix (notmuch, key);
+       query_field.flags = NOTMUCH_FIELD_PROBABILISTIC
+           | NOTMUCH_FIELD_EXTERNAL;
+
+       _setup_query_field_default (&query_field, notmuch);
+    }
+
+    notmuch_config_list_destroy (list);
+
+    return NOTMUCH_STATUS_SUCCESS;
+}
+
 #if HAVE_XAPIAN_FIELD_PROCESSOR
 static void
 _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch)
 #if HAVE_XAPIAN_FIELD_PROCESSOR
 static void
 _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch)
@@ -986,6 +1022,7 @@ notmuch_database_open_verbose (const char *path,
                _setup_query_field (prefix, notmuch);
            }
        }
                _setup_query_field (prefix, notmuch);
            }
        }
+       status = _setup_user_query_fields (notmuch);
     } catch (const Xapian::Error &error) {
        IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
                                 error.get_msg().c_str()));
     } catch (const Xapian::Error &error) {
        IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
                                 error.get_msg().c_str()));
index df32d39cb7a38a1025de40a52a889f720d0021ff..39d11a917b20a7f256f707829438b88ea0cfe379 100644 (file)
@@ -676,6 +676,8 @@ struct _notmuch_indexopts {
     _notmuch_crypto_t crypto;
 };
 
     _notmuch_crypto_t crypto;
 };
 
+#define CONFIG_HEADER_PREFIX "index.header."
+
 NOTMUCH_END_DECLS
 
 #ifdef __cplusplus
 NOTMUCH_END_DECLS
 
 #ifdef __cplusplus
index b97b00b6ce47fdced664119f99c6c30ac90fe88f..2d6cc60b6f293772299fd4c38615ffa725133995 100755 (executable)
@@ -70,4 +70,25 @@ index.header.Spam=X-Spam
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "parse user prefix"
+NOTMUCH_DEBUG_QUERY=t notmuch count 'List:"notmuch"' 2>&1 | grep Tmail >OUTPUT
+cat <<EOF > EXPECTED
+Query((Tmail AND XUList:notmuch@1))
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "parse user prefix, stemmed"
+NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuch' 2>&1 | grep Tmail >OUTPUT
+cat <<EOF > EXPECTED
+Query((Tmail AND ZXUList:notmuch@1))
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "parse user prefix, phrase"
+NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuchmail.org' 2>&1 | grep Tmail >OUTPUT
+cat <<EOF > EXPECTED
+Query((Tmail AND (XUList:notmuchmail@1 PHRASE 2 XUList:org@2)))
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
 test_done