1 Return-Path: <amthrax@awakening.csail.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 A323641A557
\r
6 for <notmuch@notmuchmail.org>; Wed, 22 Dec 2010 22:00:53 -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 KRu6E21Pl0aF for <notmuch@notmuchmail.org>;
\r
16 Wed, 22 Dec 2010 22:00:51 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id CA5C8431FB6
\r
20 for <notmuch@notmuchmail.org>; Wed, 22 Dec 2010 22:00:49 -0800 (PST)
\r
21 X-AuditID: 12074424-b7b0bae000000a05-76-4d12e590d017
\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Brightmail Gateway) with
\r
24 SMTP id D6.28.02565.095E21D4; Thu, 23 Dec 2010 01:00:48 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id oBN60lVr002450;
\r
27 Thu, 23 Dec 2010 01:00:47 -0500
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\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 oBN60kOj004800
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Thu, 23 Dec 2010 01:00:47 -0500 (EST)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72)
\r
35 (envelope-from <amthrax@awakening.csail.mit.edu>)
\r
36 id 1PVeEI-00024I-Ma; Thu, 23 Dec 2010 01:00:46 -0500
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH 2/2] Replace Xapian query parser with custom query parser.
\r
40 Date: Thu, 23 Dec 2010 01:00:24 -0500
\r
41 Message-Id: <1293084024-7893-3-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.7.2.3
\r
43 In-Reply-To: <1293084024-7893-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1293084024-7893-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: Thu, 23 Dec 2010 06:00:54 -0000
\r
61 Note that the type:mail filter is implemented as a transform pass, so
\r
62 it no longer has to be done everywhere queries are parsed.
\r
63 Furthermore, this filter now depends on the prefixing logic in the
\r
64 query parser instead of implementing this itself.
\r
66 lib/database-private.h | 3 +--
\r
67 lib/database.cc | 36 ++++++++++++++++++++++--------------
\r
68 lib/query.cc | 42 ++++++++++++------------------------------
\r
69 3 files changed, 35 insertions(+), 46 deletions(-)
\r
71 diff --git a/lib/database-private.h b/lib/database-private.h
\r
72 index 358a71b..578d1fe 100644
\r
73 --- a/lib/database-private.h
\r
74 +++ b/lib/database-private.h
\r
75 @@ -48,9 +48,8 @@ struct _notmuch_database {
\r
76 unsigned int last_doc_id;
\r
77 uint64_t last_thread_id;
\r
79 - Xapian::QueryParser *query_parser;
\r
80 Xapian::TermGenerator *term_gen;
\r
81 - Xapian::ValueRangeProcessor *value_range_processor;
\r
82 + _notmuch_qparser_t *query_parser;
\r
85 /* Return the list of terms from the given iterator matching a prefix.
\r
86 diff --git a/lib/database.cc b/lib/database.cc
\r
87 index f8245ab..d019777 100644
\r
88 --- a/lib/database.cc
\r
89 +++ b/lib/database.cc
\r
90 @@ -571,6 +571,20 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
\r
91 return NOTMUCH_STATUS_SUCCESS;
\r
94 +static _notmuch_token_t *
\r
95 +transform_type_mail (_notmuch_token_t *root, void *opaque)
\r
97 + _notmuch_token_t *nroot,
\r
98 + *mail_ast = _notmuch_token_create (root, TOK_LIT, "mail");
\r
99 + mail_ast->prefix = talloc_strdup (root, _find_prefix ("type"));
\r
102 + nroot = _notmuch_token_create (root, TOK_AND, NULL);
\r
103 + nroot->left = mail_ast;
\r
104 + nroot->right = root;
\r
108 notmuch_database_t *
\r
109 notmuch_database_open (const char *path,
\r
110 notmuch_database_mode_t mode)
\r
111 @@ -661,27 +675,24 @@ notmuch_database_open (const char *path,
\r
112 INTERNAL_ERROR ("Malformed database last_thread_id: %s", str);
\r
115 - notmuch->query_parser = new Xapian::QueryParser;
\r
116 notmuch->term_gen = new Xapian::TermGenerator;
\r
117 notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
\r
118 - notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
\r
120 - notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
\r
121 - notmuch->query_parser->set_database (*notmuch->xapian_db);
\r
122 - notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));
\r
123 - notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
\r
124 - notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
\r
125 + notmuch->query_parser = _notmuch_qparser_create (notmuch, notmuch);
\r
127 for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
\r
128 prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
\r
129 - notmuch->query_parser->add_boolean_prefix (prefix->name,
\r
131 + _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,
\r
132 + prefix->prefix, TRUE);
\r
135 for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) {
\r
136 prefix_t *prefix = &PROBABILISTIC_PREFIX[i];
\r
137 - notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);
\r
138 + _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,
\r
139 + prefix->prefix, FALSE);
\r
142 + _notmuch_qparser_add_transform (notmuch->query_parser,
\r
143 + transform_type_mail, NULL);
\r
144 } catch (const Xapian::Error &error) {
\r
145 fprintf (stderr, "A Xapian exception occurred opening database: %s\n",
\r
146 error.get_msg().c_str());
\r
147 @@ -711,9 +722,6 @@ notmuch_database_close (notmuch_database_t *notmuch)
\r
150 delete notmuch->term_gen;
\r
151 - delete notmuch->query_parser;
\r
152 - delete notmuch->xapian_db;
\r
153 - delete notmuch->value_range_processor;
\r
154 talloc_free (notmuch);
\r
157 diff --git a/lib/query.cc b/lib/query.cc
\r
158 index c7ae4ee..d68e408 100644
\r
161 @@ -131,28 +131,19 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
162 talloc_set_destructor (messages, _notmuch_messages_destructor);
\r
164 Xapian::Enquire enquire (*notmuch->xapian_db);
\r
165 - Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
\r
166 - _find_prefix ("type"),
\r
168 - Xapian::Query string_query, final_query;
\r
169 + _notmuch_token_t *ast;
\r
170 + Xapian::Query final_query;
\r
172 - unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
\r
173 - Xapian::QueryParser::FLAG_PHRASE |
\r
174 - Xapian::QueryParser::FLAG_LOVEHATE |
\r
175 - Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE |
\r
176 - Xapian::QueryParser::FLAG_WILDCARD |
\r
177 - Xapian::QueryParser::FLAG_PURE_NOT);
\r
179 if (strcmp (query_string, "") == 0 ||
\r
180 strcmp (query_string, "*") == 0)
\r
182 - final_query = mail_query;
\r
185 - string_query = notmuch->query_parser->
\r
186 - parse_query (query_string, flags);
\r
187 - final_query = Xapian::Query (Xapian::Query::OP_AND,
\r
188 - mail_query, string_query);
\r
189 + ast = _notmuch_qparser_parse (notmuch->query_parser, query_string);
\r
191 + ast = _notmuch_qparser_transform (notmuch->query_parser, ast);
\r
192 + final_query = _notmuch_qparser_generate (notmuch->query_parser, ast);
\r
194 enquire.set_weighting_scheme (Xapian::BoolWeight());
\r
196 @@ -412,28 +403,19 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
199 Xapian::Enquire enquire (*notmuch->xapian_db);
\r
200 - Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
\r
201 - _find_prefix ("type"),
\r
203 - Xapian::Query string_query, final_query;
\r
204 + _notmuch_token_t *ast;
\r
205 + Xapian::Query final_query;
\r
207 - unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
\r
208 - Xapian::QueryParser::FLAG_PHRASE |
\r
209 - Xapian::QueryParser::FLAG_LOVEHATE |
\r
210 - Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE |
\r
211 - Xapian::QueryParser::FLAG_WILDCARD |
\r
212 - Xapian::QueryParser::FLAG_PURE_NOT);
\r
214 if (strcmp (query_string, "") == 0 ||
\r
215 strcmp (query_string, "*") == 0)
\r
217 - final_query = mail_query;
\r
220 - string_query = notmuch->query_parser->
\r
221 - parse_query (query_string, flags);
\r
222 - final_query = Xapian::Query (Xapian::Query::OP_AND,
\r
223 - mail_query, string_query);
\r
224 + ast = _notmuch_qparser_parse (notmuch->query_parser, query_string);
\r
226 + ast = _notmuch_qparser_transform (notmuch->query_parser, ast);
\r
227 + final_query = _notmuch_qparser_generate (notmuch->query_parser, ast);
\r
229 enquire.set_weighting_scheme(Xapian::BoolWeight());
\r
230 enquire.set_docid_order(Xapian::Enquire::ASCENDING);
\r