diff options
| author | David Bremner <david@tethera.net> | 2022-08-14 12:02:59 -0300 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2022-09-03 08:43:33 -0300 |
| commit | 2e5ef69fbf9ce9d67720d5d4abba3026302734e5 (patch) | |
| tree | b122d17950f5d228c4616ed819ddeab633867591 /lib | |
| parent | 93c602a82fdbd03e0104ea922d073b2b1aa6b241 (diff) | |
lib: add field processor for lastmod: prefix
By sharing the existing logic used by the sexp query parser, this
allows negative lastmod revisions to be interpreted as relative to the
most recent revision.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/lastmod-fp.cc | 15 | ||||
| -rw-r--r-- | lib/lastmod-fp.h | 41 | ||||
| -rw-r--r-- | lib/open.cc | 4 |
3 files changed, 58 insertions, 2 deletions
diff --git a/lib/lastmod-fp.cc b/lib/lastmod-fp.cc index 5fdaf281..f85efd28 100644 --- a/lib/lastmod-fp.cc +++ b/lib/lastmod-fp.cc @@ -21,6 +21,7 @@ */ #include "database-private.h" +#include "lastmod-fp.h" notmuch_status_t _notmuch_lastmod_strings_to_query (notmuch_database_t *notmuch, @@ -66,3 +67,17 @@ _notmuch_lastmod_strings_to_query (notmuch_database_t *notmuch, Xapian::sortable_serialise (to_idx)); return NOTMUCH_STATUS_SUCCESS; } + +Xapian::Query +LastModRangeProcessor::operator() (const std::string &begin, const std::string &end) +{ + + Xapian::Query output; + std::string msg; + + if (_notmuch_lastmod_strings_to_query (notmuch, begin, end, output, msg)) + throw Xapian::QueryParserError (msg); + + return output; +} + diff --git a/lib/lastmod-fp.h b/lib/lastmod-fp.h new file mode 100644 index 00000000..8168fe7b --- /dev/null +++ b/lib/lastmod-fp.h @@ -0,0 +1,41 @@ +/* lastmod-fp.h - database revision query glue + * + * This file is part of notmuch. + * + * Copyright © 2022 David Bremner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/ . + * + * Author: David Bremner <david@tethera.net> + */ + +#ifndef NOTMUCH_LASTMOD_FP_H +#define NOTMUCH_LASTMOD_FP_H + +#include <xapian.h> + +class LastModRangeProcessor : public Xapian::RangeProcessor { +protected: + notmuch_database_t *notmuch; + +public: + LastModRangeProcessor (notmuch_database_t *notmuch_, const std::string prefix_) + : Xapian::RangeProcessor (NOTMUCH_VALUE_LAST_MOD, prefix_, 0), notmuch (notmuch_) + { + } + + Xapian::Query operator() (const std::string &begin, const std::string &end); +}; + +#endif /* NOTMUCH_LASTMOD_FP_H */ diff --git a/lib/open.cc b/lib/open.cc index caa58ff6..67ff868c 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -3,6 +3,7 @@ #include "database-private.h" #include "parse-time-vrp.h" +#include "lastmod-fp.h" #include "path-util.h" #if HAVE_XAPIAN_DB_RETRY_LOCK @@ -489,8 +490,7 @@ _finish_open (notmuch_database_t *notmuch, notmuch->value_range_processor = new Xapian::NumberRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); notmuch->date_range_processor = new ParseTimeRangeProcessor (NOTMUCH_VALUE_TIMESTAMP, "date:"); - notmuch->last_mod_range_processor = new Xapian::NumberRangeProcessor (NOTMUCH_VALUE_LAST_MOD, - "lastmod:"); + notmuch->last_mod_range_processor = new LastModRangeProcessor (notmuch, "lastmod:"); notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); notmuch->query_parser->set_database (*notmuch->xapian_db); notmuch->stemmer = new Xapian::Stem ("english"); |
