[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / a4 / 1c1f2327628c911ac6faa858e93c77413204b5
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 CB25042D2BD\r
6         for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:35 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\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 9XxQpwK7JjgL for <notmuch@notmuchmail.org>;\r
16         Sun, 16 Jan 2011 00:11:33 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id A3B5242D297\r
20         for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:23 -0800 (PST)\r
21 X-AuditID: 1209190f-b7c1dae000000a2b-c5-4d32a82bfdcf\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with\r
24         SMTP id 7C.E2.02603.B28A23D4; Sun, 16 Jan 2011 03:11:23 -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 p0G8BNLQ024330; \r
27         Sun, 16 Jan 2011 03:11:23 -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 p0G8BLVw010521\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sun, 16 Jan 2011 03:11:22 -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 1PeNhp-0002XX-6E; Sun, 16 Jan 2011 03:11:21 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 4/8] Replace Xapian query parser with custom query parser.\r
40 Date: Sun, 16 Jan 2011 03:10:54 -0500\r
41 Message-Id: <1295165458-9573-5-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
49 Precedence: list\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:36 -0000\r
60 \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.  Likewise, we don't\r
65 need to special-case the queries "" and "*" in multiple places.\r
66 ---\r
67  lib/database-private.h |    3 +-\r
68  lib/database.cc        |   33 ++++++++++++++-----------\r
69  lib/query.cc           |   62 ++++++++++++++++++-----------------------------\r
70  3 files changed, 44 insertions(+), 54 deletions(-)\r
71 \r
72 diff --git a/lib/database-private.h b/lib/database-private.h\r
73 index 5d2fa02..a6eea87 100644\r
74 --- a/lib/database-private.h\r
75 +++ b/lib/database-private.h\r
76 @@ -48,9 +48,8 @@ struct _notmuch_database {\r
77      unsigned int last_doc_id;\r
78      uint64_t last_thread_id;\r
79  \r
80 -    Xapian::QueryParser *query_parser;\r
81      Xapian::TermGenerator *term_gen;\r
82 -    Xapian::ValueRangeProcessor *value_range_processor;\r
83 +    _notmuch_qparser_t *query_parser;\r
84  };\r
85  \r
86  /* Return the list of terms from the given iterator matching a prefix.\r
87 diff --git a/lib/database.cc b/lib/database.cc\r
88 index f8245ab..a3df0ae 100644\r
89 --- a/lib/database.cc\r
90 +++ b/lib/database.cc\r
91 @@ -571,6 +571,17 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
92      return NOTMUCH_STATUS_SUCCESS;\r
93  }\r
94  \r
95 +static _notmuch_token_t *\r
96 +transform_type_mail (_notmuch_token_t *root, unused (void *opaque))\r
97 +{\r
98 +    _notmuch_token_t *mail_ast =\r
99 +       _notmuch_token_create_term (root, TOK_LIT, "mail");\r
100 +    mail_ast->prefix = talloc_strdup (root, _find_prefix ("type"));\r
101 +    if (!root)\r
102 +       return mail_ast;\r
103 +    return _notmuch_token_create_op (root, TOK_AND, mail_ast, root);\r
104 +}\r
105 +\r
106  notmuch_database_t *\r
107  notmuch_database_open (const char *path,\r
108                        notmuch_database_mode_t mode)\r
109 @@ -661,27 +672,24 @@ notmuch_database_open (const char *path,\r
110                 INTERNAL_ERROR ("Malformed database last_thread_id: %s", str);\r
111         }\r
112  \r
113 -       notmuch->query_parser = new Xapian::QueryParser;\r
114         notmuch->term_gen = new Xapian::TermGenerator;\r
115         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
116 -       notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
117 -\r
118 -       notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
119 -       notmuch->query_parser->set_database (*notmuch->xapian_db);\r
120 -       notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));\r
121 -       notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);\r
122 -       notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);\r
123 +       notmuch->query_parser = _notmuch_qparser_create (notmuch, notmuch);\r
124  \r
125         for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
126             prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
127 -           notmuch->query_parser->add_boolean_prefix (prefix->name,\r
128 -                                                      prefix->prefix);\r
129 +           _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,\r
130 +                                           prefix->prefix, TRUE);\r
131         }\r
132  \r
133         for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) {\r
134             prefix_t *prefix = &PROBABILISTIC_PREFIX[i];\r
135 -           notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);\r
136 +           _notmuch_qparser_add_db_prefix (notmuch->query_parser, prefix->name,\r
137 +                                           prefix->prefix, FALSE);\r
138         }\r
139 +\r
140 +       _notmuch_qparser_add_transform (notmuch->query_parser,\r
141 +                                       transform_type_mail, NULL);\r
142      } catch (const Xapian::Error &error) {\r
143         fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
144                  error.get_msg().c_str());\r
145 @@ -711,9 +719,6 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
146      }\r
147  \r
148      delete notmuch->term_gen;\r
149 -    delete notmuch->query_parser;\r
150 -    delete notmuch->xapian_db;\r
151 -    delete notmuch->value_range_processor;\r
152      talloc_free (notmuch);\r
153  }\r
154  \r
155 diff --git a/lib/query.cc b/lib/query.cc\r
156 index c7ae4ee..993f498 100644\r
157 --- a/lib/query.cc\r
158 +++ b/lib/query.cc\r
159 @@ -131,27 +131,21 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
160         talloc_set_destructor (messages, _notmuch_messages_destructor);\r
161  \r
162         Xapian::Enquire enquire (*notmuch->xapian_db);\r
163 -       Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
164 -                                                  _find_prefix ("type"),\r
165 -                                                  "mail"));\r
166 -       Xapian::Query string_query, final_query;\r
167 +       _notmuch_token_t *ast;\r
168 +       Xapian::Query final_query;\r
169         Xapian::MSet mset;\r
170 -       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
171 -                             Xapian::QueryParser::FLAG_PHRASE |\r
172 -                             Xapian::QueryParser::FLAG_LOVEHATE |\r
173 -                             Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE |\r
174 -                             Xapian::QueryParser::FLAG_WILDCARD |\r
175 -                             Xapian::QueryParser::FLAG_PURE_NOT);\r
176 +       char *error;\r
177  \r
178 -       if (strcmp (query_string, "") == 0 ||\r
179 -           strcmp (query_string, "*") == 0)\r
180 -       {\r
181 -           final_query = mail_query;\r
182 -       } else {\r
183 -           string_query = notmuch->query_parser->\r
184 -               parse_query (query_string, flags);\r
185 -           final_query = Xapian::Query (Xapian::Query::OP_AND,\r
186 -                                        mail_query, string_query);\r
187 +       ast = _notmuch_qparser_parse (query, notmuch->query_parser,\r
188 +                                     query_string);\r
189 +       ast = _notmuch_qparser_transform (notmuch->query_parser, ast);\r
190 +       final_query = _notmuch_qparser_generate (query, notmuch->query_parser,\r
191 +                                                ast, &error);\r
192 +       if (error) {\r
193 +           fprintf (stderr, "Query error: %s\n", error);\r
194 +           notmuch->exception_reported = TRUE;\r
195 +           talloc_free (messages);\r
196 +           return NULL;\r
197         }\r
198  \r
199         enquire.set_weighting_scheme (Xapian::BoolWeight());\r
200 @@ -412,27 +406,19 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
201  \r
202      try {\r
203         Xapian::Enquire enquire (*notmuch->xapian_db);\r
204 -       Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
205 -                                                  _find_prefix ("type"),\r
206 -                                                  "mail"));\r
207 -       Xapian::Query string_query, final_query;\r
208 +       _notmuch_token_t *ast;\r
209 +       Xapian::Query final_query;\r
210         Xapian::MSet mset;\r
211 -       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
212 -                             Xapian::QueryParser::FLAG_PHRASE |\r
213 -                             Xapian::QueryParser::FLAG_LOVEHATE |\r
214 -                             Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE |\r
215 -                             Xapian::QueryParser::FLAG_WILDCARD |\r
216 -                             Xapian::QueryParser::FLAG_PURE_NOT);\r
217 +       char *error;\r
218  \r
219 -       if (strcmp (query_string, "") == 0 ||\r
220 -           strcmp (query_string, "*") == 0)\r
221 -       {\r
222 -           final_query = mail_query;\r
223 -       } else {\r
224 -           string_query = notmuch->query_parser->\r
225 -               parse_query (query_string, flags);\r
226 -           final_query = Xapian::Query (Xapian::Query::OP_AND,\r
227 -                                        mail_query, string_query);\r
228 +       ast = _notmuch_qparser_parse (query, notmuch->query_parser,\r
229 +                                     query_string);\r
230 +       ast = _notmuch_qparser_transform (notmuch->query_parser, ast);\r
231 +       final_query = _notmuch_qparser_generate (query, notmuch->query_parser,\r
232 +                                                ast, &error);\r
233 +       if (error) {\r
234 +           fprintf (stderr, "Query error: %s\n", error);\r
235 +           return count;\r
236         }\r
237  \r
238         enquire.set_weighting_scheme(Xapian::BoolWeight());\r
239 -- \r
240 1.7.2.3\r
241 \r