--- /dev/null
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 88056429E2F\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:39 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id cBjJsomRgZk7 for <notmuch@notmuchmail.org>;\r
+ Sun, 16 Jan 2011 00:11:38 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+ [18.9.25.13])\r
+ by olra.theworths.org (Postfix) with ESMTP id 823F342D29B\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:25 -0800 (PST)\r
+X-AuditID: 1209190d-b7cacae000000a14-a8-4d32a82df995\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ by dmz-mailsec-scanner-2.mit.edu (Symantec Brightmail Gateway) with\r
+ SMTP id 5A.C7.02580.D28A23D4; Sun, 16 Jan 2011 03:11:25 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id p0G8BPcR024334; \r
+ Sun, 16 Jan 2011 03:11:25 -0500\r
+Received: from drake.mit.edu (a074.catapulsion.net [70.36.81.74])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0G8BNLT010530\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Sun, 16 Jan 2011 03:11:24 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.72)\r
+ (envelope-from <amthrax@drake.mit.edu>)\r
+ id 1PeNhr-0002Xg-0w; Sun, 16 Jan 2011 03:11:23 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 7/8] Implement value range queries.\r
+Date: Sun, 16 Jan 2011 03:10:57 -0500\r
+Message-Id: <1295165458-9573-8-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
+References: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker: AAAAAA==\r
+Cc: amdragon@mit.edu\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 16 Jan 2011 08:11:40 -0000\r
+\r
+Unlike in Xapian, there's no specific syntax that generates value\r
+ranges. Instead, it's up query transforms to generate them.\r
+---\r
+ lib/notmuch-private.h | 8 ++++++++\r
+ lib/qparser.cc | 20 +++++++++++++++++---\r
+ 2 files changed, 25 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 5fc54de..9c16f56 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -548,6 +548,8 @@ enum _notmuch_token_type {\r
+ * with no phrase splitting or whitespace removal. The lexer\r
+ * only generates TOK_TERMS; the parser creates TOK_LIT. */\r
+ TOK_LIT,\r
++ /* A value range operand. */\r
++ TOK_RANGE,\r
+ /* An error token. An error token anywhere in the parse tree will\r
+ * be propagated up by the generator and returned to the caller.\r
+ * The error message should be in the text. */\r
+@@ -577,6 +579,12 @@ typedef struct _notmuch_token {\r
+ * match any terms prefixed with text. */\r
+ notmuch_bool_t wildcard;\r
+ \r
++ /* For TOK_RANGE, the value number to filter on, and the\r
++ * (inclusive) range to match lexicographically. Either endpoint\r
++ * may be NULL, indicating an open-ended range. */\r
++ unsigned valueno;\r
++ const char *rangeBegin, *rangeEnd;\r
++\r
+ /* Link in the lexer token list. */\r
+ struct _notmuch_token *next;\r
+ \r
+diff --git a/lib/qparser.cc b/lib/qparser.cc\r
+index 0ff240c..2c63062 100644\r
+--- a/lib/qparser.cc\r
++++ b/lib/qparser.cc\r
+@@ -43,7 +43,6 @@\r
+ * Still missing from this implementation:\r
+ * * Stemming - The stemming should probably be marked on TOK_TERMS\r
+ * tokens. Ideally, we can just pass this to the term generator.\r
+- * * Value ranges in the IR\r
+ */\r
+ \r
+ /* XXX notmuch currently registers "tag" as an exclusive boolean\r
+@@ -100,13 +99,13 @@ static const char *token_types[] = {\r
+ "LOVE", "HATE", "BRA", "KET",\r
+ "AND", "OR", "XOR", "ADJ", "NEAR",\r
+ "NOT", "FILTER", "PREFIX",\r
+- "TERMS", "LIT", "ERROR", "END"\r
++ "TERMS", "LIT", "ERROR", "RANGE", "END"\r
+ };\r
+ \r
+ /* The distinguished end token. This simplifies the parser since it\r
+ * never has to worry about dereferencing next. */\r
+ static _notmuch_token_t tok_end = {TOK_END, NULL, -1, FALSE, NULL, FALSE,\r
+- &tok_end, NULL, NULL};\r
++ 0, NULL, NULL, &tok_end, NULL, NULL};\r
+ \r
+ _notmuch_token_t *\r
+ _notmuch_token_create_op (const void *ctx, enum _notmuch_token_type type,\r
+@@ -145,6 +144,9 @@ _notmuch_token_show (const void *ctx, _notmuch_token_t *tok)\r
+ else if (tok->type == TOK_LIT)\r
+ return talloc_asprintf (ctx, "'%s'%s", tok->text,\r
+ tok->wildcard ? "*" : "");\r
++ else if (tok->type == TOK_RANGE)\r
++ return talloc_asprintf (ctx, "RANGE/%d:%s..%s",\r
++ tok->valueno, tok->rangeBegin, tok->rangeEnd);\r
+ else if (tok->type == TOK_ERROR)\r
+ return talloc_asprintf (ctx, "ERROR/\"%s\"", tok->text);\r
+ \r
+@@ -536,6 +538,7 @@ parse_prob (struct _notmuch_parse_state *s, int prec, _notmuch_token_t **tok)\r
+ break;\r
+ \r
+ case TOK_FILTER:\r
++ case TOK_RANGE:\r
+ case TOK_ERROR:\r
+ INTERNAL_ERROR ("Unexpected token %s",\r
+ _notmuch_token_show (s->ctx, *tok));\r
+@@ -902,6 +905,17 @@ generate (struct _notmuch_generate_state *s, _notmuch_token_t *root)\r
+ return generate_wildcard (s, term);\r
+ return Query (term);\r
+ \r
++ case TOK_RANGE:\r
++ if (root->rangeBegin && root->rangeEnd)\r
++ return Query (Query::OP_VALUE_RANGE, root->valueno,\r
++ root->rangeBegin, root->rangeEnd);\r
++ else if (root->rangeBegin)\r
++ return Query (Query::OP_VALUE_GE, root->valueno, root->rangeBegin);\r
++ else if (root->rangeEnd)\r
++ return Query (Query::OP_VALUE_LE, root->valueno, root->rangeEnd);\r
++ else\r
++ INTERNAL_ERROR ("TOK_RANGE must have an endpoint");\r
++\r
+ case TOK_ERROR:\r
+ if (!s->error)\r
+ s->error = talloc_strdup (s->ctx, root->text);\r
+-- \r
+1.7.2.3\r
+\r