I was answering a question today about the s-expression query parser and I realized that date and lastmod never got implemented. This series implements them (they were already documented, so no documentation changes).
This is documented, but apparently not implemented. Add tests for planned supported syntax and error messages. --- test/T081-sexpr-search.sh | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 2a8ad5f1..d8f8872d 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -768,6 +768,78 @@ notmuch search date:2009-11-18..2009-11-18 and tag:unread > EXPECTED notmuch search --query=sexp '(and (infix "date:2009-11-18..2009-11-18") (infix "tag:unread"))' > OUTPUT test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "date query, empty" +test_subtest_known_broken +notmuch search from:keithp | notmuch_search_sanitize > EXPECTED +notmuch search --query=sexp '(and (date) (from keithp))'| notmuch_search_sanitize > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, one argument" +test_subtest_known_broken +notmuch search date:2009-11-18 and from:keithp | notmuch_search_sanitize > EXPECTED +notmuch search --query=sexp '(and (date 2009-11-18) (from keithp))' | notmuch_search_sanitize > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, two arguments" +test_subtest_known_broken +notmuch search date:2009-11-17..2009-11-18 and from:keithp | notmuch_search_sanitize > EXPECTED +notmuch search --query=sexp '(and (date 2009-11-17 2009-11-18) (from keithp))' | notmuch_search_sanitize > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, illegal nesting 1" +test_subtest_known_broken +notmuch search --query=sexp '(to (date))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +nested field: 'date' inside 'to' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, illegal nesting 2" +test_subtest_known_broken +notmuch search --query=sexp '(to (date 2021-11-18))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +nested field: 'date' inside 'to' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, illegal nesting 3" +test_subtest_known_broken +notmuch search --query=sexp '(date (to))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +expected atom as first argument of 'date' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, illegal nesting 4" +test_subtest_known_broken +notmuch search --query=sexp '(date today (to))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +expected atom as second argument of 'date' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, too many arguments" +test_subtest_known_broken +notmuch search --query=sexp '(date yesterday and tommorow)' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +'date' expects maximum of two arguments +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "date query, bad date" +test_subtest_known_broken +notmuch search --query=sexp '(date "hawaiian-pizza-day")' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +Didn't understand date specification 'hawaiian-pizza-day' +EOF +test_expect_equal_file EXPECTED OUTPUT + test_begin_subtest "user header (unknown header)" notmuch search --query=sexp '(FooBar)' >& OUTPUT cat <<EOF > EXPECTED -- 2.34.1
These are not too practical, although they may simplify some user query generation code. Mainly this adds a new prefix keyword to the parser. --- lib/parse-sexp.cc | 22 +++++++++++++++++++++- test/T081-sexpr-search.sh | 3 --- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index 356c32ea..f36d18a6 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -32,6 +32,7 @@ typedef enum { SEXP_FLAG_EXPAND = 1 << 6, SEXP_FLAG_DO_EXPAND = 1 << 7, SEXP_FLAG_ORPHAN = 1 << 8, + SEXP_FLAG_RANGE = 1 << 9, } _sexp_flag_t; /* @@ -66,6 +67,8 @@ static _sexp_prefix_t prefixes[] = SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_EXPAND }, { "body", Xapian::Query::OP_AND, Xapian::Query::MatchAll, SEXP_FLAG_FIELD }, + { "date", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll, + SEXP_FLAG_RANGE }, { "from", Xapian::Query::OP_AND, Xapian::Query::MatchAll, SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND }, { "folder", Xapian::Query::OP_OR, Xapian::Query::MatchNothing, @@ -446,6 +449,19 @@ _sexp_expand_param (notmuch_database_t *notmuch, const _sexp_prefix_t *parent, return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; } +static notmuch_status_t +_sexp_parse_date (notmuch_database_t *notmuch, const sexp_t *sx, Xapian::Query &output) +{ + /* empty date matches everything */ + if (! sx) { + output = Xapian::Query::MatchAll; + return NOTMUCH_STATUS_SUCCESS; + } + + _notmuch_database_log (notmuch, "unimplemented date query\n"); + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; +} + /* Here we expect the s-expression to be a proper list, with first * element defining and operation, or as a special case the empty * list */ @@ -519,7 +535,7 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, const _sexp_prefix_t *parent for (_sexp_prefix_t *prefix = prefixes; prefix && prefix->name; prefix++) { if (strcmp (prefix->name, sx->list->val) == 0) { - if (prefix->flags & SEXP_FLAG_FIELD) { + if (prefix->flags & (SEXP_FLAG_FIELD | SEXP_FLAG_RANGE)) { if (parent) { _notmuch_database_log (notmuch, "nested field: '%s' inside '%s'\n", prefix->name, parent->name); @@ -541,6 +557,10 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, const _sexp_prefix_t *parent return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; } + if (strcmp (prefix->name, "date") == 0) { + return _sexp_parse_date (notmuch, sx->list->next, output); + } + if (strcmp (prefix->name, "infix") == 0) { return _sexp_parse_infix (notmuch, sx->list->next, output); } diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index d8f8872d..a6e2ee82 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -769,7 +769,6 @@ notmuch search --query=sexp '(and (infix "date:2009-11-18..2009-11-18") (infix test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, empty" -test_subtest_known_broken notmuch search from:keithp | notmuch_search_sanitize > EXPECTED notmuch search --query=sexp '(and (date) (from keithp))'| notmuch_search_sanitize > OUTPUT test_expect_equal_file EXPECTED OUTPUT @@ -787,7 +786,6 @@ notmuch search --query=sexp '(and (date 2009-11-17 2009-11-18) (from keithp))' test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, illegal nesting 1" -test_subtest_known_broken notmuch search --query=sexp '(to (date))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -796,7 +794,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, illegal nesting 2" -test_subtest_known_broken notmuch search --query=sexp '(to (date 2021-11-18))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query -- 2.34.1
This will allow re-using the same logic in the s-expression parser. --- lib/database-private.h | 5 +++++ lib/parse-time-vrp.cc | 51 +++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index 8133e364..1663ae3c 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -374,5 +374,10 @@ notmuch_status_t _notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr, Xapian::Query &output); #endif + +/* parse-time-vrp.h */ +notmuch_status_t +_notmuch_date_strings_to_query (Xapian::valueno slot, const std::string &from, const std::string &to, + Xapian::Query &output, std::string &msg); #endif #endif diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc index 22bf2ab5..6b07970b 100644 --- a/lib/parse-time-vrp.cc +++ b/lib/parse-time-vrp.cc @@ -24,22 +24,28 @@ #include "parse-time-vrp.h" #include "parse-time-string.h" -Xapian::Query -ParseTimeRangeProcessor::operator() (const std::string &begin, const std::string &end) +notmuch_status_t +_notmuch_date_strings_to_query (Xapian::valueno slot, + const std::string &begin, const std::string &end, + Xapian::Query &output, std::string &msg) { double from = DBL_MIN, to = DBL_MAX; time_t parsed_time, now; std::string str; /* Use the same 'now' for begin and end. */ - if (time (&now) == (time_t) -1) - throw Xapian::QueryParserError ("unable to get current time"); + if (time (&now) == (time_t) -1) { + msg = "unable to get current time"; + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + } if (! begin.empty ()) { - if (parse_time_string (begin.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_DOWN)) - throw Xapian::QueryParserError ("Didn't understand date specification '" + begin + "'"); - else - from = (double) parsed_time; + if (parse_time_string (begin.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_DOWN)) { + msg = "Didn't understand date specification '" + begin + "'"; + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } + + from = (double) parsed_time; } if (! end.empty ()) { @@ -48,15 +54,30 @@ ParseTimeRangeProcessor::operator() (const std::string &begin, const std::string else str = end; - if (parse_time_string (str.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_UP_INCLUSIVE)) - throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'"); - else - to = (double) parsed_time; + if (parse_time_string (str.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_UP_INCLUSIVE)) { + msg = "Didn't understand date specification '" + str + "'"; + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } + to = (double) parsed_time; } - return Xapian::Query (Xapian::Query::OP_VALUE_RANGE, slot, - Xapian::sortable_serialise (from), - Xapian::sortable_serialise (to)); + output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, slot, + Xapian::sortable_serialise (from), + Xapian::sortable_serialise (to)); + return NOTMUCH_STATUS_SUCCESS; +} + +Xapian::Query +ParseTimeRangeProcessor::operator() (const std::string &begin, const std::string &end) +{ + + Xapian::Query output; + std::string msg; + + if (_notmuch_date_strings_to_query (slot, begin, end, output, msg)) + throw Xapian::QueryParserError (msg); + + return output; } /* XXX TODO: is throwing an exception the right thing to do here? */ -- 2.34.1
The default argument processing overlaps somewhat with what is already done in _notmuch_date_strings_to_query, but we can give more specific error messages for the s-expression context. The extra generality of _sexp_parse_range will be useful when we implement additional range prefixes (at least 'lastmod' is needed). --- lib/parse-sexp.cc | 41 +++++++++++++++++++++++++++++++++------ test/T081-sexpr-search.sh | 5 ----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index f36d18a6..fa88071e 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -450,15 +450,45 @@ _sexp_expand_param (notmuch_database_t *notmuch, const _sexp_prefix_t *parent, } static notmuch_status_t -_sexp_parse_date (notmuch_database_t *notmuch, const sexp_t *sx, Xapian::Query &output) +_sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix, + const sexp_t *sx, Xapian::Query &output) { - /* empty date matches everything */ + const char *from, *to; + std::string msg; /* ignored */ + + /* empty range matches everything */ if (! sx) { output = Xapian::Query::MatchAll; return NOTMUCH_STATUS_SUCCESS; } - _notmuch_database_log (notmuch, "unimplemented date query\n"); + if (sx->ty == SEXP_LIST) { + _notmuch_database_log (notmuch, "expected atom as first argument of '%s'\n", prefix->name); + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } + + from = sx->val; + to = from; + + if (sx->next) { + if (sx->next->ty == SEXP_LIST) { + _notmuch_database_log (notmuch, "expected atom as second argument of '%s'\n", + prefix->name); + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } + + if (sx->next->next) { + _notmuch_database_log (notmuch, "'%s' expects maximum of two arguments\n", prefix->name); + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } + + to = sx->next->val; + } + + if (strcmp (prefix->name, "date") == 0) + return _notmuch_date_strings_to_query (NOTMUCH_VALUE_TIMESTAMP, from, to, output, msg); + + _notmuch_database_log (notmuch, "unimplimented range prefix: '%s'\n", prefix->name); return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; } @@ -557,9 +587,8 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, const _sexp_prefix_t *parent return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; } - if (strcmp (prefix->name, "date") == 0) { - return _sexp_parse_date (notmuch, sx->list->next, output); - } + if (prefix->flags & SEXP_FLAG_RANGE) + return _sexp_parse_range (notmuch, prefix, sx->list->next, output); if (strcmp (prefix->name, "infix") == 0) { return _sexp_parse_infix (notmuch, sx->list->next, output); diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index a6e2ee82..ea55c2b2 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -774,13 +774,11 @@ notmuch search --query=sexp '(and (date) (from keithp))'| notmuch_search_saniti test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, one argument" -test_subtest_known_broken notmuch search date:2009-11-18 and from:keithp | notmuch_search_sanitize > EXPECTED notmuch search --query=sexp '(and (date 2009-11-18) (from keithp))' | notmuch_search_sanitize > OUTPUT test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, two arguments" -test_subtest_known_broken notmuch search date:2009-11-17..2009-11-18 and from:keithp | notmuch_search_sanitize > EXPECTED notmuch search --query=sexp '(and (date 2009-11-17 2009-11-18) (from keithp))' | notmuch_search_sanitize > OUTPUT test_expect_equal_file EXPECTED OUTPUT @@ -802,7 +800,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, illegal nesting 3" -test_subtest_known_broken notmuch search --query=sexp '(date (to))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -811,7 +808,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, illegal nesting 4" -test_subtest_known_broken notmuch search --query=sexp '(date today (to))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -820,7 +816,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, too many arguments" -test_subtest_known_broken notmuch search --query=sexp '(date yesterday and tommorow)' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query -- 2.34.1
These are loosely modelled on the tests just above for date ranges, since the error conditions are similar. Some ideas also borrowed from T570-revision-tracking. --- test/T081-sexpr-search.sh | 85 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index ea55c2b2..0b4ecf8e 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -832,6 +832,91 @@ Didn't understand date specification 'hawaiian-pizza-day' EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "lastmod query, empty" +test_subtest_known_broken +notmuch search from:keithp | notmuch_search_sanitize > EXPECTED +notmuch search --query=sexp '(and (lastmod) (from keithp))'| notmuch_search_sanitize > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, one argument" +test_subtest_known_broken +notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org +revision=$(notmuch count --lastmod '*' | cut -f3) +notmuch search lastmod:$revision..$revision | notmuch_search_sanitize > EXPECTED +notmuch search --query=sexp "(and (lastmod $revision))" | notmuch_search_sanitize > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, two arguments" +test_subtest_known_broken +notmuch tag +keithp from:keithp +revision2=$(notmuch count --lastmod '*' | cut -f3) +notmuch search lastmod:$revision..$revision2 | notmuch_search_sanitize > EXPECTED +notmuch search --query=sexp "(and (lastmod $revision $revision2))" | notmuch_search_sanitize > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, illegal nesting 1" +test_subtest_known_broken +notmuch search --query=sexp '(to (lastmod))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +nested field: 'lastmod' inside 'to' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, bad from revision" +test_subtest_known_broken +notmuch search --query=sexp '(lastmod apples)' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +bad 'from' revision: 'apples' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, bad to revision" +test_subtest_known_broken +notmuch search --query=sexp '(lastmod 0 apples)' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +bad 'to' revision: 'apples' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, illegal nesting 2" +test_subtest_known_broken +notmuch search --query=sexp '(to (lastmod 2021-11-18))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +nested field: 'lastmod' inside 'to' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, illegal nesting 3" +test_subtest_known_broken +notmuch search --query=sexp '(lastmod (to))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +expected atom as first argument of 'lastmod' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, illegal nesting 4" +test_subtest_known_broken +notmuch search --query=sexp '(lastmod today (to))' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +expected atom as second argument of 'lastmod' +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "lastmod query, too many arguments" +test_subtest_known_broken +notmuch search --query=sexp '(lastmod yesterday and tommorow)' > OUTPUT 2>&1 +cat <<EOF > EXPECTED +notmuch search: Syntax error in query +'lastmod' expects maximum of two arguments +EOF +test_expect_equal_file EXPECTED OUTPUT + test_begin_subtest "user header (unknown header)" notmuch search --query=sexp '(FooBar)' >& OUTPUT cat <<EOF > EXPECTED -- 2.34.1
This particular choice of converting strings to integers requires C++11. --- lib/parse-sexp.cc | 38 +++++++++++++++++++++++++++++++++++--- test/T081-sexpr-search.sh | 11 ----------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index fa88071e..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, @@ -454,7 +456,7 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix, const sexp_t *sx, Xapian::Query &output) { const char *from, *to; - std::string msg; /* ignored */ + std::string msg; /* empty range matches everything */ if (! sx) { @@ -485,8 +487,38 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix, to = sx->next->val; } - if (strcmp (prefix->name, "date") == 0) - return _notmuch_date_strings_to_query (NOTMUCH_VALUE_TIMESTAMP, from, to, output, msg); + if (strcmp (prefix->name, "date") == 0) { + notmuch_status_t status; + status = _notmuch_date_strings_to_query (NOTMUCH_VALUE_TIMESTAMP, from, to, output, msg); + if (status) { + if (! msg.empty ()) + _notmuch_database_log (notmuch, "%s\n", msg.c_str ()); + } + 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; diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 0b4ecf8e..73f45041 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -824,7 +824,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, bad date" -test_subtest_known_broken notmuch search --query=sexp '(date "hawaiian-pizza-day")' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -833,13 +832,11 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, empty" -test_subtest_known_broken notmuch search from:keithp | notmuch_search_sanitize > EXPECTED notmuch search --query=sexp '(and (lastmod) (from keithp))'| notmuch_search_sanitize > OUTPUT test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, one argument" -test_subtest_known_broken notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org revision=$(notmuch count --lastmod '*' | cut -f3) notmuch search lastmod:$revision..$revision | notmuch_search_sanitize > EXPECTED @@ -847,7 +844,6 @@ notmuch search --query=sexp "(and (lastmod $revision))" | notmuch_search_saniti test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, two arguments" -test_subtest_known_broken notmuch tag +keithp from:keithp revision2=$(notmuch count --lastmod '*' | cut -f3) notmuch search lastmod:$revision..$revision2 | notmuch_search_sanitize > EXPECTED @@ -855,7 +851,6 @@ notmuch search --query=sexp "(and (lastmod $revision $revision2))" | notmuch_se test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 1" -test_subtest_known_broken notmuch search --query=sexp '(to (lastmod))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -864,7 +859,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, bad from revision" -test_subtest_known_broken notmuch search --query=sexp '(lastmod apples)' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -873,7 +867,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, bad to revision" -test_subtest_known_broken notmuch search --query=sexp '(lastmod 0 apples)' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -882,7 +875,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 2" -test_subtest_known_broken notmuch search --query=sexp '(to (lastmod 2021-11-18))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -891,7 +883,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 3" -test_subtest_known_broken notmuch search --query=sexp '(lastmod (to))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -900,7 +891,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 4" -test_subtest_known_broken notmuch search --query=sexp '(lastmod today (to))' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query @@ -909,7 +899,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, too many arguments" -test_subtest_known_broken notmuch search --query=sexp '(lastmod yesterday and tommorow)' > OUTPUT 2>&1 cat <<EOF > EXPECTED notmuch search: Syntax error in query -- 2.34.1