Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 30 / fdcfefb6f73a772475c5045f611bc8aad644a7
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 5367F6DE092A\r
6  for <notmuch@notmuchmail.org>; Sat,  7 May 2016 17:06:56 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.013\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.013 tagged_above=-999 required=5\r
12  tests=[AWL=-0.002, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
13  autolearn=disabled\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 eeUMJH97-oRA for <notmuch@notmuchmail.org>;\r
17  Sat,  7 May 2016 17:06:48 -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 251B06DE092C\r
20  for <notmuch@notmuchmail.org>; Sat,  7 May 2016 17:05:08 -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 1azCDW-00016L-2g; Sat, 07 May 2016 20:05:02 -0400\r
24 Received: (nullmailer pid 17183 invoked by uid 1000);\r
25  Sun, 08 May 2016 00:04:53 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [Patch v4 02/12] lib: optionally support single argument date:\r
29  queries\r
30 Date: Sat,  7 May 2016 21:04:39 -0300\r
31 Message-Id: <1462665889-17121-3-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 2.8.1\r
33 In-Reply-To: <1462665889-17121-1-git-send-email-david@tethera.net>\r
34 References: <1462665889-17121-1-git-send-email-david@tethera.net>\r
35 MIME-Version: 1.0\r
36 Content-Type: text/plain; charset=UTF-8\r
37 Content-Transfer-Encoding: 8bit\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.20\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42  <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
44  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
49  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sun, 08 May 2016 00:06:56 -0000\r
51 \r
52 This relies on the FieldProcessor API, which is only present in xapian\r
53 >= 1.3.\r
54 ---\r
55  doc/man7/notmuch-search-terms.rst | 22 +++++++++++++++++++---\r
56  lib/database-private.h            |  3 +++\r
57  lib/database.cc                   |  6 ++++++\r
58  lib/parse-time-vrp.cc             | 21 +++++++++++++++++++++\r
59  lib/parse-time-vrp.h              |  5 +++++\r
60  test/T500-search-date.sh          |  6 ++++++\r
61  6 files changed, 60 insertions(+), 3 deletions(-)\r
62 \r
63 diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst\r
64 index 2fbc16d..adedf5a 100644\r
65 --- a/doc/man7/notmuch-search-terms.rst\r
66 +++ b/doc/man7/notmuch-search-terms.rst\r
67 @@ -281,9 +281,10 @@ matches from the beginning of January to the end of February.\r
68  date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The\r
69  expansion takes place before interpretation, and thus, for example,\r
70  date:monday..! matches from the beginning of Monday until the end of\r
71 -Monday. (Note that entering date:<expr> without "..", for example\r
72 -date:yesterday, won't work, as it's not interpreted as a range\r
73 -expression at all. Again, use date:yesterday..!)\r
74 +Monday.\r
75 +With **Xapian Field Processor** support (see below), non-range\r
76 +date queries such as date:yesterday will work, but otherwise\r
77 +will give unexpected results; if in doubt use date:yesterday..!\r
78  \r
79  Currently, we do not support spaces in range expressions. You can\r
80  replace the spaces with '\_', or (in most cases) '-', or (in some cases)\r
81 @@ -370,6 +371,21 @@ Time zones\r
82  \r
83  Some time zone codes, e.g. UTC, EET.\r
84  \r
85 +XAPIAN FIELD PROCESSORS\r
86 +=======================\r
87 +\r
88 +Certain optional features of the notmuch query processor rely on the\r
89 +presence of the Xapian field processor API. You can determine if your\r
90 +notmuch was built against a sufficiently recent version of Xapian by running\r
91 +\r
92 +::\r
93 +\r
94 +  % notmuch config get built_with.field_processor\r
95 +\r
96 +Currently the following features require field processor support:\r
97 +\r
98 +- non-range date queries, e.g. "date:today"\r
99 +\r
100  SEE ALSO\r
101  ========\r
102  \r
103 diff --git a/lib/database-private.h b/lib/database-private.h\r
104 index 3fb10f7..e1962f4 100644\r
105 --- a/lib/database-private.h\r
106 +++ b/lib/database-private.h\r
107 @@ -176,6 +176,9 @@ struct _notmuch_database {\r
108      Xapian::TermGenerator *term_gen;\r
109      Xapian::ValueRangeProcessor *value_range_processor;\r
110      Xapian::ValueRangeProcessor *date_range_processor;\r
111 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
112 +    Xapian::FieldProcessor *date_field_processor;\r
113 +#endif\r
114      Xapian::ValueRangeProcessor *last_mod_range_processor;\r
115  };\r
116  \r
117 diff --git a/lib/database.cc b/lib/database.cc\r
118 index c8c5e26..ebe019f 100644\r
119 --- a/lib/database.cc\r
120 +++ b/lib/database.cc\r
121 @@ -1000,6 +1000,12 @@ notmuch_database_open_verbose (const char *path,\r
122         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
123         notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
124         notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
125 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
126 +       /* This currently relies on the query parser to pass anything\r
127 +        * with a .. to the range processor */\r
128 +       notmuch->date_field_processor = new DateFieldProcessor();\r
129 +       notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor);\r
130 +#endif\r
131         notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");\r
132  \r
133         notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
134 diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
135 index 03804cf..b15b77c 100644\r
136 --- a/lib/parse-time-vrp.cc\r
137 +++ b/lib/parse-time-vrp.cc\r
138 @@ -64,3 +64,24 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
139  \r
140      return valno;\r
141  }\r
142 +\r
143 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
144 +/* XXX TODO: is throwing an exception the right thing to do here? */\r
145 +Xapian::Query DateFieldProcessor::operator()(const std::string & str) {\r
146 +    time_t from, to, now;\r
147 +\r
148 +    /* Use the same 'now' for begin and end. */\r
149 +    if (time (&now) == (time_t) -1)\r
150 +       throw Xapian::QueryParserError("Unable to get current time");\r
151 +\r
152 +    if (parse_time_string (str.c_str (), &from, &now, PARSE_TIME_ROUND_DOWN))\r
153 +       throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");\r
154 +\r
155 +    if (parse_time_string (str.c_str (), &to, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))\r
156 +       throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");\r
157 +\r
158 +    return Xapian::Query(Xapian::Query::OP_AND,\r
159 +                        Xapian::Query(Xapian::Query::OP_VALUE_GE, 0, Xapian::sortable_serialise ((double) from)),\r
160 +                        Xapian::Query(Xapian::Query::OP_VALUE_LE, 0, Xapian::sortable_serialise ((double) to)));\r
161 +}\r
162 +#endif\r
163 diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h\r
164 index 094c4f8..3bd12bf 100644\r
165 --- a/lib/parse-time-vrp.h\r
166 +++ b/lib/parse-time-vrp.h\r
167 @@ -37,4 +37,9 @@ public:\r
168      Xapian::valueno operator() (std::string &begin, std::string &end);\r
169  };\r
170  \r
171 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
172 +class DateFieldProcessor : public Xapian::FieldProcessor {\r
173 +    Xapian::Query operator()(const std::string & str);\r
174 +};\r
175 +#endif\r
176  #endif /* NOTMUCH_PARSE_TIME_VRP_H */\r
177 diff --git a/test/T500-search-date.sh b/test/T500-search-date.sh\r
178 index f5cea42..198a2e6 100755\r
179 --- a/test/T500-search-date.sh\r
180 +++ b/test/T500-search-date.sh\r
181 @@ -12,6 +12,12 @@ test_begin_subtest "Absolute date range with 'same' operator"\r
182  output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize)\r
183  test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
184  \r
185 +if [ "${NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR}" = "1" ]; then\r
186 +    test_begin_subtest "Absolute date field"\r
187 +    output=$(notmuch search date:2010-12-16 | notmuch_search_sanitize)\r
188 +    test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
189 +fi\r
190 +\r
191  test_begin_subtest "Absolute time range with TZ"\r
192  notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT\r
193  cat <<EOF >EXPECTED\r
194 -- \r
195 2.8.1\r
196 \r