1 /* lastmod-fp.cc - lastmod range query glue
3 * This file is part of notmuch.
5 * Copyright © 2022 David Bremner
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see https://www.gnu.org/licenses/ .
20 * Author: David Bremner <david@tethera.net>
23 #include "database-private.h"
24 #include "lastmod-fp.h"
27 _notmuch_lastmod_strings_to_query (notmuch_database_t *notmuch,
28 const std::string &from, const std::string &to,
29 Xapian::Query &output, std::string &msg)
31 long from_idx = 0L, to_idx = LONG_MAX;
35 /* revision should not change, but for the avoidance of doubt,
36 * grab for both ends of range, if needed*/
37 current = notmuch_database_get_revision (notmuch, NULL);
43 from_idx = std::stol (from);
44 } catch (std::logic_error &e) {
45 msg = "bad 'from' revision: '" + from + "'";
46 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
53 if (EMPTY_STRING (to))
56 to_idx = std::stol (to);
57 } catch (std::logic_error &e) {
58 msg = "bad 'to' revision: '" + to + "'";
59 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
65 output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, NOTMUCH_VALUE_LAST_MOD,
66 Xapian::sortable_serialise (from_idx),
67 Xapian::sortable_serialise (to_idx));
68 return NOTMUCH_STATUS_SUCCESS;
72 LastModRangeProcessor::operator() (const std::string &begin, const std::string &end)
78 if (_notmuch_lastmod_strings_to_query (notmuch, begin, end, output, msg))
79 throw Xapian::QueryParserError (msg);