aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2022-01-20 09:36:05 -0400
committerDavid Bremner <david@tethera.net>2022-01-26 07:41:02 -0400
commit0a32741fceb7778ced34064eacb7b5aac2c71638 (patch)
treee154e821e124b3e21ce634fa6398e8c825d970b0 /lib
parent341016c8ec34f838c2d72dc1bbfac567df054cd9 (diff)
lib/parse-sexp: handle lastmod queries.
This particular choice of converting strings to integers requires C++11.
Diffstat (limited to 'lib')
-rw-r--r--lib/parse-sexp.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc
index dbc3f89d..06825dc4 100644
--- a/lib/parse-sexp.cc
+++ b/lib/parse-sexp.cc
@@ -79,6 +79,8 @@ static _sexp_prefix_t prefixes[] =
SEXP_FLAG_SINGLE | SEXP_FLAG_ORPHAN },
{ "is", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
+ { "lastmod", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll,
+ SEXP_FLAG_RANGE },
{ "matching", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
SEXP_FLAG_DO_EXPAND },
{ "mid", Xapian::Query::OP_OR, Xapian::Query::MatchNothing,
@@ -495,6 +497,29 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix,
return status;
}
+ if (strcmp (prefix->name, "lastmod") == 0) {
+ long from_idx, to_idx;
+
+ try {
+ from_idx = std::stol (from);
+ } catch (std::logic_error &e) {
+ _notmuch_database_log (notmuch, "bad 'from' revision: '%s'\n", from);
+ return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
+ }
+
+ try {
+ to_idx = std::stol (to);
+ } catch (std::logic_error &e) {
+ _notmuch_database_log (notmuch, "bad 'to' revision: '%s'\n", to);
+ return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
+ }
+
+ output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, NOTMUCH_VALUE_LAST_MOD,
+ Xapian::sortable_serialise (from_idx),
+ Xapian::sortable_serialise (to_idx));
+ return NOTMUCH_STATUS_SUCCESS;
+ }
+
_notmuch_database_log (notmuch, "unimplimented range prefix: '%s'\n", prefix->name);
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
}