1 Return-Path: <bremner@tethera.net>
\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 arlo.cworth.org (Postfix) with ESMTP id 360FE6DE035C
\r
6 for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:54 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.018, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 5pCk7Srnxw28 for <notmuch@notmuchmail.org>;
\r
17 Tue, 22 Mar 2016 03:55:43 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id 811256DE02AD
\r
20 for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:22 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1aiJyf-00015D-Vw; Tue, 22 Mar 2016 06:55:58 -0400
\r
24 Received: (nullmailer pid 14093 invoked by uid 1000);
\r
25 Tue, 22 Mar 2016 10:55:11 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH 13/13] lib: add support for named queries
\r
29 Date: Tue, 22 Mar 2016 07:54:54 -0300
\r
30 Message-Id: <1458644094-13951-14-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.7.0
\r
32 In-Reply-To: <1458644094-13951-1-git-send-email-david@tethera.net>
\r
33 References: <1458644094-13951-1-git-send-email-david@tethera.net>
\r
35 Content-Type: text/plain; charset=UTF-8
\r
36 Content-Transfer-Encoding: 8bit
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.20
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Tue, 22 Mar 2016 10:55:54 -0000
\r
51 This relies on the optional presense of xapian field processors, and the
\r
54 lib/Makefile.local | 1 +
\r
55 lib/database-private.h | 2 ++
\r
56 lib/database.cc | 3 +++
\r
57 lib/query-fp.cc | 42 ++++++++++++++++++++++++++++++++++++++++++
\r
58 lib/query-fp.h | 42 ++++++++++++++++++++++++++++++++++++++++++
\r
59 test/T600-named-queries.sh | 17 +++++++++++++++++
\r
60 6 files changed, 107 insertions(+)
\r
61 create mode 100644 lib/query-fp.cc
\r
62 create mode 100644 lib/query-fp.h
\r
64 diff --git a/lib/Makefile.local b/lib/Makefile.local
\r
65 index 96899bf..fab1242 100644
\r
66 --- a/lib/Makefile.local
\r
67 +++ b/lib/Makefile.local
\r
68 @@ -49,6 +49,7 @@ libnotmuch_cxx_srcs = \
\r
72 + $(dir)/query-fp.cc \
\r
76 diff --git a/lib/database-private.h b/lib/database-private.h
\r
77 index 59708d0..f7c6f46 100644
\r
78 --- a/lib/database-private.h
\r
79 +++ b/lib/database-private.h
\r
80 @@ -150,6 +150,7 @@ operator&=(_notmuch_features &a, _notmuch_features b)
\r
82 #if HAVE_XAPIAN_FIELD_PROCESSOR
\r
83 class DateFieldProcessor;
\r
84 +class QueryFieldProcessor;
\r
86 struct _notmuch_database {
\r
87 notmuch_bool_t exception_reported;
\r
88 @@ -185,6 +186,7 @@ struct _notmuch_database {
\r
89 Xapian::ValueRangeProcessor *date_range_processor;
\r
90 #if HAVE_XAPIAN_FIELD_PROCESSOR
\r
91 DateFieldProcessor *date_field_processor;
\r
92 + QueryFieldProcessor *query_field_processor;
\r
94 Xapian::ValueRangeProcessor *last_mod_range_processor;
\r
96 diff --git a/lib/database.cc b/lib/database.cc
\r
97 index 0e3c90c..8df5555 100644
\r
98 --- a/lib/database.cc
\r
99 +++ b/lib/database.cc
\r
102 #include "database-private.h"
\r
103 #include "parse-time-vrp.h"
\r
104 +#include "query-fp.h"
\r
105 #include "string-util.h"
\r
107 #include <iostream>
\r
108 @@ -1005,6 +1006,8 @@ notmuch_database_open_verbose (const char *path,
\r
109 * with a .. to the range processor */
\r
110 notmuch->date_field_processor = new DateFieldProcessor();
\r
111 notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor);
\r
112 + notmuch->query_field_processor = new QueryFieldProcessor (*notmuch->query_parser, notmuch);
\r
113 + notmuch->query_parser->add_boolean_prefix("query", notmuch->query_field_processor);
\r
115 notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");
\r
117 diff --git a/lib/query-fp.cc b/lib/query-fp.cc
\r
118 new file mode 100644
\r
119 index 0000000..ee5a306
\r
121 +++ b/lib/query-fp.cc
\r
123 +/* query-fp.cc - "query:" field processor glue glue
\r
125 + * This file is part of notmuch.
\r
127 + * Copyright © 2016 David Bremner
\r
129 + * This program is free software: you can redistribute it and/or modify
\r
130 + * it under the terms of the GNU General Public License as published by
\r
131 + * the Free Software Foundation, either version 3 of the License, or
\r
132 + * (at your option) any later version.
\r
134 + * This program is distributed in the hope that it will be useful,
\r
135 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
136 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
137 + * GNU General Public License for more details.
\r
139 + * You should have received a copy of the GNU General Public License
\r
140 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
142 + * Author: David Bremner <david@tethera.net>
\r
145 +#include "database-private.h"
\r
146 +#include "query-fp.h"
\r
147 +#include <iostream>
\r
149 +#if HAVE_XAPIAN_FIELD_PROCESSOR
\r
151 +Xapian::Query QueryFieldProcessor::operator()(const std::string & name) {
\r
152 + std::string key = "query." + name;
\r
154 + notmuch_status_t status;
\r
156 + status = notmuch_database_get_config (notmuch, key.c_str(), &expansion);
\r
158 + throw Xapian::QueryParserError("error looking up key" + name);
\r
162 + return parser.parse_query (expansion, NOTMUCH_QUERY_PARSER_FLAGS);
\r
165 diff --git a/lib/query-fp.h b/lib/query-fp.h
\r
166 new file mode 100644
\r
167 index 0000000..67f8705
\r
169 +++ b/lib/query-fp.h
\r
171 +/* query-fp.h - query field processor glue
\r
173 + * This file is part of notmuch.
\r
175 + * Copyright © 2016 David Bremner
\r
177 + * This program is free software: you can redistribute it and/or modify
\r
178 + * it under the terms of the GNU General Public License as published by
\r
179 + * the Free Software Foundation, either version 3 of the License, or
\r
180 + * (at your option) any later version.
\r
182 + * This program is distributed in the hope that it will be useful,
\r
183 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
184 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
185 + * GNU General Public License for more details.
\r
187 + * You should have received a copy of the GNU General Public License
\r
188 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
190 + * Author: David Bremner <david@tethera.net>
\r
193 +#ifndef NOTMUCH_QUERY_FP_H
\r
194 +#define NOTMUCH_QUERY_FP_H
\r
196 +#include <xapian.h>
\r
197 +#include "notmuch.h"
\r
199 +#if HAVE_XAPIAN_FIELD_PROCESSOR
\r
200 +class QueryFieldProcessor : public Xapian::FieldProcessor {
\r
202 + Xapian::QueryParser &parser;
\r
203 + notmuch_database_t *notmuch;
\r
206 + QueryFieldProcessor (Xapian::QueryParser &parser_, notmuch_database_t *notmuch_)
\r
207 + : parser(parser_), notmuch(notmuch_) { };
\r
209 + Xapian::Query operator()(const std::string & str);
\r
212 +#endif /* NOTMUCH_QUERY_FP_H */
\r
213 diff --git a/test/T600-named-queries.sh b/test/T600-named-queries.sh
\r
214 index 0922620..f0ae24f 100755
\r
215 --- a/test/T600-named-queries.sh
\r
216 +++ b/test/T600-named-queries.sh
\r
217 @@ -50,4 +50,21 @@ notmuch restore < BEFORE
\r
218 notmuch dump | grep '^#@' > OUTPUT
\r
219 test_expect_equal_file QUERIES.BEFORE OUTPUT
\r
221 +if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -eq 1 ]; then
\r
222 + test_begin_subtest "search named query"
\r
223 + notmuch search query:test > OUTPUT
\r
224 + notmuch search $QUERYSTR > EXPECTED
\r
225 + test_expect_equal_file EXPECTED OUTPUT
\r
227 + test_begin_subtest "search named query with other terms"
\r
228 + notmuch search query:test and subject:Maildir > OUTPUT
\r
229 + notmuch search $QUERYSTR and subject:Maildir > EXPECTED
\r
230 + test_expect_equal_file EXPECTED OUTPUT
\r
232 + test_begin_subtest "search nested named query"
\r
233 + notmuch search query:test2 > OUTPUT
\r
234 + notmuch search $QUERYSTR2 > EXPECTED
\r
235 + test_expect_equal_file EXPECTED OUTPUT
\r