unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Cc: amdragon@mit.edu
Subject: [PATCH 5/8] Support "tag:*" as well as "NOT tag:*" queries.
Date: Sun, 16 Jan 2011 03:10:55 -0500	[thread overview]
Message-ID: <1295165458-9573-6-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu>

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

  parent reply	other threads:[~2011-01-16  8:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-16  8:10 [RFC PATCH v2 0/8] Custom query parser, date search, folder search, and more Austin Clements
2011-01-16  8:10 ` [PATCH 1/8] Implement a custom query parser with a mostly Xapian-compatible grammar Austin Clements
2011-01-21  6:37   ` [PATCH 1.5/8] Query parser testing framework and basic tests Austin Clements
2011-01-16  8:10 ` [PATCH 2/8] Parse NEAR and ADJ operators Austin Clements
2011-01-21  6:39   ` [PATCH 2.5/8] Query parser tests for " Austin Clements
2011-01-16  8:10 ` [PATCH 3/8] Parse wildcard queries Austin Clements
2011-01-21  6:40   ` [PATCH 3.5/8] Query parser tests for " Austin Clements
2011-01-22 16:47     ` Michal Sojka
2011-01-23 22:02       ` Austin Clements
2011-01-24 12:24         ` Michal Sojka
2011-01-16  8:10 ` [PATCH 4/8] Replace Xapian query parser with custom query parser Austin Clements
2011-01-16  8:10 ` Austin Clements [this message]
2011-01-24 17:15   ` [PATCH 5.5/8] test: Wildcard tag search and untagged search Austin Clements
2011-01-16  8:10 ` [PATCH 6/8] Support maildir folder search Austin Clements
2011-01-24 17:13   ` [PATCH 6/8 v2] " Austin Clements
2011-01-24 17:18   ` [PATCH 6.5/8] test: Add tests for custom query parser-based folder searches Austin Clements
2011-01-16  8:10 ` [PATCH 7/8] Implement value range queries Austin Clements
2011-01-16  8:10 ` [PATCH 8/8] Support before: and after: date search with sane date syntax Austin Clements
2011-01-24 17:20   ` [PATCH 8.5/8] test: Add tests for search by date Austin Clements
2011-01-31  4:33 ` [PATCH 9/8] qparser: Delete (and thus close) the Xapian database Austin Clements
2011-02-02  5:03 ` [RFC PATCH v2 0/8] Custom query parser, date search, folder search, and more Austin Clements
2011-02-02 22:48   ` Carl Worth
2011-02-03  6:14     ` Folder search semantics (was Re: [RFC PATCH v2 0/8] Custom query parser, date search, folder search, and more) Austin Clements
2011-02-20 19:52       ` Folder search semantics Rob Browning
2011-02-20 20:00         ` Rob Browning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295165458-9573-6-git-send-email-amdragon@mit.edu \
    --to=amdragon@mit.edu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).