1 Return-Path: <amthrax@drake.mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 88056429E2F
\r
6 for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:39 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id cBjJsomRgZk7 for <notmuch@notmuchmail.org>;
\r
16 Sun, 16 Jan 2011 00:11:38 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 823F342D29B
\r
20 for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:25 -0800 (PST)
\r
21 X-AuditID: 1209190d-b7cacae000000a14-a8-4d32a82df995
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-2.mit.edu (Symantec Brightmail Gateway) with
\r
24 SMTP id 5A.C7.02580.D28A23D4; Sun, 16 Jan 2011 03:11:25 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id p0G8BPcR024334;
\r
27 Sun, 16 Jan 2011 03:11:25 -0500
\r
28 Received: from drake.mit.edu (a074.catapulsion.net [70.36.81.74])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0G8BNLT010530
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Sun, 16 Jan 2011 03:11:24 -0500 (EST)
\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.72)
\r
35 (envelope-from <amthrax@drake.mit.edu>)
\r
36 id 1PeNhr-0002Xg-0w; Sun, 16 Jan 2011 03:11:23 -0500
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH 7/8] Implement value range queries.
\r
40 Date: Sun, 16 Jan 2011 03:10:57 -0500
\r
41 Message-Id: <1295165458-9573-8-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.7.2.3
\r
43 In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1295165458-9573-1-git-send-email-amdragon@mit.edu>
\r
45 X-Brightmail-Tracker: AAAAAA==
\r
46 Cc: amdragon@mit.edu
\r
47 X-BeenThere: notmuch@notmuchmail.org
\r
48 X-Mailman-Version: 2.1.13
\r
50 List-Id: "Use and development of the notmuch mail system."
\r
51 <notmuch.notmuchmail.org>
\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
55 List-Post: <mailto:notmuch@notmuchmail.org>
\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
59 X-List-Received-Date: Sun, 16 Jan 2011 08:11:40 -0000
\r
61 Unlike in Xapian, there's no specific syntax that generates value
\r
62 ranges. Instead, it's up query transforms to generate them.
\r
64 lib/notmuch-private.h | 8 ++++++++
\r
65 lib/qparser.cc | 20 +++++++++++++++++---
\r
66 2 files changed, 25 insertions(+), 3 deletions(-)
\r
68 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
69 index 5fc54de..9c16f56 100644
\r
70 --- a/lib/notmuch-private.h
\r
71 +++ b/lib/notmuch-private.h
\r
72 @@ -548,6 +548,8 @@ enum _notmuch_token_type {
\r
73 * with no phrase splitting or whitespace removal. The lexer
\r
74 * only generates TOK_TERMS; the parser creates TOK_LIT. */
\r
76 + /* A value range operand. */
\r
78 /* An error token. An error token anywhere in the parse tree will
\r
79 * be propagated up by the generator and returned to the caller.
\r
80 * The error message should be in the text. */
\r
81 @@ -577,6 +579,12 @@ typedef struct _notmuch_token {
\r
82 * match any terms prefixed with text. */
\r
83 notmuch_bool_t wildcard;
\r
85 + /* For TOK_RANGE, the value number to filter on, and the
\r
86 + * (inclusive) range to match lexicographically. Either endpoint
\r
87 + * may be NULL, indicating an open-ended range. */
\r
89 + const char *rangeBegin, *rangeEnd;
\r
91 /* Link in the lexer token list. */
\r
92 struct _notmuch_token *next;
\r
94 diff --git a/lib/qparser.cc b/lib/qparser.cc
\r
95 index 0ff240c..2c63062 100644
\r
96 --- a/lib/qparser.cc
\r
97 +++ b/lib/qparser.cc
\r
99 * Still missing from this implementation:
\r
100 * * Stemming - The stemming should probably be marked on TOK_TERMS
\r
101 * tokens. Ideally, we can just pass this to the term generator.
\r
102 - * * Value ranges in the IR
\r
105 /* XXX notmuch currently registers "tag" as an exclusive boolean
\r
106 @@ -100,13 +99,13 @@ static const char *token_types[] = {
\r
107 "LOVE", "HATE", "BRA", "KET",
\r
108 "AND", "OR", "XOR", "ADJ", "NEAR",
\r
109 "NOT", "FILTER", "PREFIX",
\r
110 - "TERMS", "LIT", "ERROR", "END"
\r
111 + "TERMS", "LIT", "ERROR", "RANGE", "END"
\r
114 /* The distinguished end token. This simplifies the parser since it
\r
115 * never has to worry about dereferencing next. */
\r
116 static _notmuch_token_t tok_end = {TOK_END, NULL, -1, FALSE, NULL, FALSE,
\r
117 - &tok_end, NULL, NULL};
\r
118 + 0, NULL, NULL, &tok_end, NULL, NULL};
\r
121 _notmuch_token_create_op (const void *ctx, enum _notmuch_token_type type,
\r
122 @@ -145,6 +144,9 @@ _notmuch_token_show (const void *ctx, _notmuch_token_t *tok)
\r
123 else if (tok->type == TOK_LIT)
\r
124 return talloc_asprintf (ctx, "'%s'%s", tok->text,
\r
125 tok->wildcard ? "*" : "");
\r
126 + else if (tok->type == TOK_RANGE)
\r
127 + return talloc_asprintf (ctx, "RANGE/%d:%s..%s",
\r
128 + tok->valueno, tok->rangeBegin, tok->rangeEnd);
\r
129 else if (tok->type == TOK_ERROR)
\r
130 return talloc_asprintf (ctx, "ERROR/\"%s\"", tok->text);
\r
132 @@ -536,6 +538,7 @@ parse_prob (struct _notmuch_parse_state *s, int prec, _notmuch_token_t **tok)
\r
138 INTERNAL_ERROR ("Unexpected token %s",
\r
139 _notmuch_token_show (s->ctx, *tok));
\r
140 @@ -902,6 +905,17 @@ generate (struct _notmuch_generate_state *s, _notmuch_token_t *root)
\r
141 return generate_wildcard (s, term);
\r
142 return Query (term);
\r
145 + if (root->rangeBegin && root->rangeEnd)
\r
146 + return Query (Query::OP_VALUE_RANGE, root->valueno,
\r
147 + root->rangeBegin, root->rangeEnd);
\r
148 + else if (root->rangeBegin)
\r
149 + return Query (Query::OP_VALUE_GE, root->valueno, root->rangeBegin);
\r
150 + else if (root->rangeEnd)
\r
151 + return Query (Query::OP_VALUE_LE, root->valueno, root->rangeEnd);
\r
153 + INTERNAL_ERROR ("TOK_RANGE must have an endpoint");
\r
157 s->error = talloc_strdup (s->ctx, root->text);
\r