]> git.notmuchmail.org Git - notmuch/blobdiff - database.cc
Add bash-completion script for notmuch.
[notmuch] / database.cc
index 7a3019e1de0a708f31c9daba6ca0e81e9144509d..1666aff0a123d9d5c156ee20d8dc2c30d5b21602 100644 (file)
@@ -41,26 +41,11 @@ typedef struct {
     const char *prefix;
 } prefix_t;
 
-prefix_t NORMAL_PREFIX[] = {
-    { "subject", "S" },
-    { "body", "B" },
-    { "from_name", "FN" },
-    { "to_name", "TN" },
-    { "name", "N" },
-    { "attachment", "A" }
-};
-
 prefix_t BOOLEAN_PREFIX[] = {
     { "type", "K" },
-    { "from_email", "FE" },
-    { "to_email", "TE" },
-    { "email", "E" },
-    { "date", "D" },
-    { "label", "L" },
     { "tag", "L" },
-    { "source_id", "I" },
-    { "attachment_extension", "O" },
     { "msgid", "Q" },
+    { "id", "Q" },
     { "thread", "H" },
     { "ref", "R" },
     { "timestamp", "KTS" },
@@ -71,10 +56,6 @@ _find_prefix (const char *name)
 {
     unsigned int i;
 
-    for (i = 0; i < ARRAY_SIZE (NORMAL_PREFIX); i++)
-       if (strcmp (name, NORMAL_PREFIX[i].name) == 0)
-           return NORMAL_PREFIX[i].prefix;
-
     for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX); i++)
        if (strcmp (name, BOOLEAN_PREFIX[i].name) == 0)
            return BOOLEAN_PREFIX[i].prefix;
@@ -513,6 +494,9 @@ notmuch_database_open (const char *path)
        notmuch->query_parser = new Xapian::QueryParser;
        notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
        notmuch->query_parser->set_database (*notmuch->xapian_db);
+       notmuch->query_parser->add_boolean_prefix ("id", _find_prefix ("id"));
+       notmuch->query_parser->add_boolean_prefix ("tag", _find_prefix ("tag"));
+       notmuch->query_parser->add_boolean_prefix ("type", _find_prefix ("type"));
     } catch (const Xapian::Error &error) {
        fprintf (stderr, "A Xapian exception occurred: %s\n",
                 error.get_msg().c_str());
@@ -562,11 +546,12 @@ find_timestamp_document (notmuch_database_t *notmuch, const char *db_key,
 static char *
 timestamp_db_key (const char *key)
 {
-    if (strlen (key) + 1 > NOTMUCH_TERM_MAX) {
+    int term_len = strlen (_find_prefix ("timestamp")) + strlen (key);
+
+    if (term_len > NOTMUCH_TERM_MAX)
        return notmuch_sha1_of_string (key);
-    } else {
+    else
        return strdup (key);
-    }
 }
 
 notmuch_status_t