Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 8CD18429E2F for ; Sun, 16 Jan 2011 00:11:37 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GjxYcuRLpr0m for ; Sun, 16 Jan 2011 00:11:35 -0800 (PST) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id 5C77B42D299 for ; Sun, 16 Jan 2011 00:11:24 -0800 (PST) X-AuditID: 1209190c-b7ba9ae0000009f8-bc-4d32a82c0e73 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-1.mit.edu (Symantec Brightmail Gateway) with SMTP id AB.ED.02552.C28A23D4; Sun, 16 Jan 2011 03:11:24 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p0G8BNhu004721; Sun, 16 Jan 2011 03:11:23 -0500 Received: from drake.mit.edu (a074.catapulsion.net [70.36.81.74]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0G8BMTW010524 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 16 Jan 2011 03:11:23 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.72) (envelope-from ) id 1PeNhp-0002Xa-Tq; Sun, 16 Jan 2011 03:11:21 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 5/8] Support "tag:*" as well as "NOT tag:*" queries. Date: Sun, 16 Jan 2011 03:10:55 -0500 Message-Id: <1295165458-9573-6-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu> References: <1295165458-9573-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: AAAAAA== Cc: amdragon@mit.edu X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Jan 2011 08:11:37 -0000 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