This extends the syntactic-to-database prefix query transform to
optionally expand wildcards for boolean prefixes.  Support of "NOT
tag:*" queries to find all untagged messages falls out as a convenient
side-effect.
---
 TODO                  |    2 --
 lib/database.cc       |    4 ++--
 lib/notmuch-private.h |   10 ++++++----
 lib/qparser.cc        |   12 +++++++++++-
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/TODO b/TODO
index 10c8c12..15606d1 100644
--- a/TODO
+++ b/TODO
@@ -220,8 +220,6 @@ Fix the "count" functionality to be exact as Olly explained 
in IRC:
 
 Search syntax
 -------------
-Implement support for "tag:*" to expand to all tags.
-
 Fix "notmuch search to:" to be less confusing. Many users expect this
 to search for all messages with a To: header, but it instead searches
 for all messages with the word "to". If we don't provide the first
diff --git a/lib/database.cc b/lib/database.cc
index a3df0ae..3af82b0 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -679,13 +679,13 @@ notmuch_database_open (const char *path,
        for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
            prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
            _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,
-                                           prefix->prefix, TRUE);
+                                           prefix->prefix, TRUE, TRUE);
        }
 
        for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) {
            prefix_t *prefix = &PROBABILISTIC_PREFIX[i];
            _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,
-                                           prefix->prefix, FALSE);
+                                           prefix->prefix, FALSE, FALSE);
        }
 
        _notmuch_qparser_add_transform (notmuch->query_parser,
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index eb346ea..5fc54de 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -631,13 +631,15 @@ _notmuch_qparser_add_transform (_notmuch_qparser_t 
*qparser,
                                void *opaque);
 
 /* Add a syntactic prefix (field) and a transform pass to transform
- * that syntactic prefix into a database prefix (prefix).  This
- * corresponds to Xapian's add_prefix and add_boolean_prefix
- * functions. */
+ * that syntactic prefix into a database prefix (prefix).  For boolean
+ * prefixes, wildcard indicates whether the term should allow wildcard
+ * expansion.  This corresponds to Xapian's add_prefix and
+ * add_boolean_prefix functions. */
 void
 _notmuch_qparser_add_db_prefix (_notmuch_qparser_t *qparser,
                                const char *field, const char *prefix,
-                               notmuch_bool_t boolean);
+                               notmuch_bool_t boolean,
+                               notmuch_bool_t wildcard);
 
 /* Lex a query string, returning the first token in the token list.
  * This is only meant for testing. */
diff --git a/lib/qparser.cc b/lib/qparser.cc
index bd0296a..0ff240c 100644
--- a/lib/qparser.cc
+++ b/lib/qparser.cc
@@ -974,6 +974,7 @@ _notmuch_qparser_add_transform (_notmuch_qparser_t *qparser,
 
 struct _notmuch_transform_prefix_info {
     char *field, *prefix;
+    notmuch_bool_t wildcard;
 };
 
 static _notmuch_token_t *
@@ -986,6 +987,13 @@ transform_prefix_rec (struct 
_notmuch_transform_prefix_info *info,
        active = (strcmp (info->field, root->text) == 0);
     } else if (active && (root->type == TOK_TERMS || root->type == TOK_LIT)) {
        root->prefix = info->prefix;
+       if (info->wildcard) {
+           int n = strlen (root->text);
+           if (n && root->text[n - 1] == '*') {
+               root->text = talloc_strndup (root, root->text, n - 1);
+               root->wildcard = TRUE;
+           }
+       }
     }
     transform_prefix_rec (info, root->left, active);
     transform_prefix_rec (info, root->right, active);
@@ -1003,12 +1011,14 @@ transform_prefix (_notmuch_token_t *root, void *opaque)
 void
 _notmuch_qparser_add_db_prefix (_notmuch_qparser_t *qparser,
                                const char *field, const char *prefix,
-                               notmuch_bool_t boolean)
+                               notmuch_bool_t boolean,
+                               notmuch_bool_t wildcard)
 {
     struct _notmuch_transform_prefix_info *info;
     info = talloc (qparser, struct _notmuch_transform_prefix_info);
     info->field = talloc_strdup (info, field);
     info->prefix = talloc_strdup (info, prefix);
+    info->wildcard = boolean && wildcard;
     _notmuch_qparser_add_prefix (qparser, field, boolean, boolean);
     _notmuch_qparser_add_transform (qparser, transform_prefix, info);
 }
-- 
1.7.2.3

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to