Re: Linking a privately built -lxapian
[notmuch-archives.git] / 9c / c397e5e96b5584164ec83696919b43ccac9bf8
1 Return-Path: <jani@nikula.org>\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 D9CCF431FCB\r
6         for <notmuch@notmuchmail.org>; Wed, 12 Sep 2012 14:27:56 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id VKfyg6K8JI8c for <notmuch@notmuchmail.org>;\r
17         Wed, 12 Sep 2012 14:27:54 -0700 (PDT)\r
18 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
19         [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id CD7C1431FBF\r
22         for <notmuch@notmuchmail.org>; Wed, 12 Sep 2012 14:27:52 -0700 (PDT)\r
23 Received: by mail-lpp01m010-f53.google.com with SMTP id c1so1533671lah.26\r
24         for <notmuch@notmuchmail.org>; Wed, 12 Sep 2012 14:27:52 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
28         :in-reply-to:references:x-gm-message-state;\r
29         bh=GAFk4XQpkm5Elii8o3aLbnjPvmijI01vxKGKR1VNlUw=;\r
30         b=J6gjzBlhciBBxyy0XciGNlWJ0FyL4qrE23T7K3Vm+LLGblSVUGKJNQYOrmpO/qkW/1\r
31         TPl48S5UbqlgbsfYhZAKI0hwxsr2MwbNcL3egjE5f1Of9ruRfq/HNtqPQCvGrFGAtaOd\r
32         icMNj9qgaUg/r3IA3FLQ+ZRqTQr9njqYZAvdkVpUCdVwwrNuewZ6i2lDWBQzfm92pb8F\r
33         So3Ah3EzUiO1msm9PfCknlwnOvy3Hju6BenyUbET2vXjn/tA2BFL1BXCsAauhWWiWReb\r
34         vSi6wU5DQj/fxS+/+ixf7Z2csbDtkKQyQr27WbtNj8elkmvyTwenUxmUCzC4R3njrKax\r
35         pLhw==\r
36 Received: by 10.112.49.197 with SMTP id w5mr167850lbn.3.1347485272390;\r
37         Wed, 12 Sep 2012 14:27:52 -0700 (PDT)\r
38 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
39         [80.223.81.27])\r
40         by mx.google.com with ESMTPS id o3sm5532049lbk.6.2012.09.12.14.27.50\r
41         (version=SSLv3 cipher=OTHER); Wed, 12 Sep 2012 14:27:51 -0700 (PDT)\r
42 From: Jani Nikula <jani@nikula.org>\r
43 To: notmuch@notmuchmail.org,\r
44         David Bremner <david@tethera.net>\r
45 Subject: [PATCH v3 6/9] lib: add date range query support\r
46 Date: Thu, 13 Sep 2012 00:27:23 +0300\r
47 Message-Id:\r
48  <532340d05ea748518c021048900bb83149e04e88.1347484177.git.jani@nikula.org>\r
49 X-Mailer: git-send-email 1.7.9.5\r
50 In-Reply-To: <cover.1347484177.git.jani@nikula.org>\r
51 References: <cover.1347484177.git.jani@nikula.org>\r
52 In-Reply-To: <cover.1347484177.git.jani@nikula.org>\r
53 References: <cover.1347484177.git.jani@nikula.org>\r
54 X-Gm-Message-State:\r
55  ALoCoQl6t0/GhDcxX63feT4amVwS7/6ILQdMBrfzrM6gV8xKKr5PLmzcfUKG4M7bzxFNySM99GJz\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Wed, 12 Sep 2012 21:27:57 -0000\r
69 \r
70 Add a custom value range processor to enable date and time searches of\r
71 the form date:since..until, where "since" and "until" are expressions\r
72 understood by the previously added date/time parser, to restrict the\r
73 results to messages within a particular time range (based on the Date:\r
74 header).\r
75 \r
76 If "since" or "until" describes date/time at an accuracy of days or\r
77 less, the values are rounded according to the accuracy, towards past\r
78 for "since" and towards future for "until". For example,\r
79 date:november..yesterday would match from the beginning of November\r
80 until the end of yesterday. Expressions such as date:today..today\r
81 means since the beginning of today until the end of today.\r
82 \r
83 Open-ended ranges are supported (since Xapian 1.2.1), i.e. you can\r
84 specify date:..until or date:since.. to not limit the start or end\r
85 date, respectively.\r
86 \r
87 CAVEATS:\r
88 \r
89 Xapian does not support spaces in range expressions. You can replace\r
90 the spaces with '_', or (in most cases) '-', or (in some cases) leave\r
91 the spaces out altogether.\r
92 \r
93 Entering date:expr without ".." (for example date:yesterday) will not\r
94 work as you might expect. You can achieve the expected result by\r
95 duplicating the expr both sides of ".." (for example\r
96 date:yesterday..yesterday).\r
97 \r
98 Open-ended ranges won't work with pre-1.2.1 Xapian, but they don't\r
99 produce an error either.\r
100 \r
101 Signed-off-by: Jani Nikula <jani@nikula.org>\r
102 ---\r
103  lib/Makefile.local     |    1 +\r
104  lib/database-private.h |    1 +\r
105  lib/database.cc        |    5 +++++\r
106  lib/parse-time-vrp.cc  |   40 ++++++++++++++++++++++++++++++++++++++++\r
107  lib/parse-time-vrp.h   |   19 +++++++++++++++++++\r
108  5 files changed, 66 insertions(+)\r
109  create mode 100644 lib/parse-time-vrp.cc\r
110  create mode 100644 lib/parse-time-vrp.h\r
111 \r
112 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
113 index d1635cf..6c0f42f 100644\r
114 --- a/lib/Makefile.local\r
115 +++ b/lib/Makefile.local\r
116 @@ -58,6 +58,7 @@ libnotmuch_c_srcs =           \\r
117  \r
118  libnotmuch_cxx_srcs =          \\r
119         $(dir)/database.cc      \\r
120 +       $(dir)/parse-time-vrp.cc        \\r
121         $(dir)/directory.cc     \\r
122         $(dir)/index.cc         \\r
123         $(dir)/message.cc       \\r
124 diff --git a/lib/database-private.h b/lib/database-private.h\r
125 index 88532d5..d3e65fd 100644\r
126 --- a/lib/database-private.h\r
127 +++ b/lib/database-private.h\r
128 @@ -52,6 +52,7 @@ struct _notmuch_database {\r
129      Xapian::QueryParser *query_parser;\r
130      Xapian::TermGenerator *term_gen;\r
131      Xapian::ValueRangeProcessor *value_range_processor;\r
132 +    Xapian::ValueRangeProcessor *date_range_processor;\r
133  };\r
134  \r
135  /* Return the list of terms from the given iterator matching a prefix.\r
136 diff --git a/lib/database.cc b/lib/database.cc\r
137 index 761dc1a..4df3217 100644\r
138 --- a/lib/database.cc\r
139 +++ b/lib/database.cc\r
140 @@ -19,6 +19,7 @@\r
141   */\r
142  \r
143  #include "database-private.h"\r
144 +#include "parse-time-vrp.h"\r
145  \r
146  #include <iostream>\r
147  \r
148 @@ -710,12 +711,14 @@ notmuch_database_open (const char *path,\r
149         notmuch->term_gen = new Xapian::TermGenerator;\r
150         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
151         notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
152 +       notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
153  \r
154         notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
155         notmuch->query_parser->set_database (*notmuch->xapian_db);\r
156         notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));\r
157         notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);\r
158         notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);\r
159 +       notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);\r
160  \r
161         for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
162             prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
163 @@ -778,6 +781,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
164      notmuch->xapian_db = NULL;\r
165      delete notmuch->value_range_processor;\r
166      notmuch->value_range_processor = NULL;\r
167 +    delete notmuch->date_range_processor;\r
168 +    notmuch->date_range_processor = NULL;\r
169  }\r
170  \r
171  void\r
172 diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
173 new file mode 100644\r
174 index 0000000..148c117\r
175 --- /dev/null\r
176 +++ b/lib/parse-time-vrp.cc\r
177 @@ -0,0 +1,40 @@\r
178 +\r
179 +#include "database-private.h"\r
180 +#include "parse-time-vrp.h"\r
181 +#include "parse-time-string.h"\r
182 +\r
183 +#define PREFIX "date:"\r
184 +\r
185 +/* See *ValueRangeProcessor in xapian-core/api/valuerangeproc.cc */\r
186 +Xapian::valueno\r
187 +ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
188 +{\r
189 +    time_t t, now;\r
190 +\r
191 +    /* Require date: prefix in start of the range... */\r
192 +    if (STRNCMP_LITERAL (begin.c_str (), PREFIX))\r
193 +       return Xapian::BAD_VALUENO;\r
194 +\r
195 +    /* ...and remove it. */\r
196 +    begin.erase (0, sizeof (PREFIX) - 1);\r
197 +\r
198 +    /* Use the same 'now' for begin and end. */\r
199 +    if (time (&now) == (time_t) -1)\r
200 +       return Xapian::BAD_VALUENO;\r
201 +\r
202 +    if (!begin.empty ()) {\r
203 +       if (parse_time_string (begin.c_str (), &t, &now, PARSE_TIME_ROUND_DOWN))\r
204 +           return Xapian::BAD_VALUENO;\r
205 +\r
206 +       begin.assign (Xapian::sortable_serialise ((double) t));\r
207 +    }\r
208 +\r
209 +    if (!end.empty ()) {\r
210 +       if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP))\r
211 +           return Xapian::BAD_VALUENO;\r
212 +\r
213 +       end.assign (Xapian::sortable_serialise ((double) t));\r
214 +    }\r
215 +\r
216 +    return valno;\r
217 +}\r
218 diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h\r
219 new file mode 100644\r
220 index 0000000..526c217\r
221 --- /dev/null\r
222 +++ b/lib/parse-time-vrp.h\r
223 @@ -0,0 +1,19 @@\r
224 +\r
225 +#ifndef NOTMUCH_PARSE_TIME_VRP_H\r
226 +#define NOTMUCH_PARSE_TIME_VRP_H\r
227 +\r
228 +#include <xapian.h>\r
229 +\r
230 +/* see *ValueRangeProcessor in xapian-core/include/xapian/queryparser.h */\r
231 +class ParseTimeValueRangeProcessor : public Xapian::ValueRangeProcessor {\r
232 +protected:\r
233 +    Xapian::valueno valno;\r
234 +\r
235 +public:\r
236 +    ParseTimeValueRangeProcessor (Xapian::valueno slot_)\r
237 +       : valno(slot_) { }\r
238 +\r
239 +    Xapian::valueno operator() (std::string &begin, std::string &end);\r
240 +};\r
241 +\r
242 +#endif /* NOTMUCH_PARSE_TIME_VRP_H */\r
243 -- \r
244 1.7.9.5\r
245 \r