* v2 add range operators to sexp queries
@ 2022-01-20 13:35 David Bremner
2022-01-20 13:36 ` [PATCH v2 1/6] test/search: add known broken tests for 'date' prefix David Bremner
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: David Bremner @ 2022-01-20 13:35 UTC (permalink / raw)
To: notmuch
Changes since v1: move some date related changes (specifically the
error message) from patch 6/6 back to patch 4/6. No change to the
final tree (i.e. interdiff is empty)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/6] test/search: add known broken tests for 'date' prefix
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
@ 2022-01-20 13:36 ` David Bremner
2022-01-20 13:36 ` [PATCH v2 2/6] lib/parse-sexp: support zero argument date queries David Bremner
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2022-01-20 13:36 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/6] lib/parse-sexp: support zero argument date queries
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
2022-01-20 13:36 ` [PATCH v2 1/6] test/search: add known broken tests for 'date' prefix David Bremner
@ 2022-01-20 13:36 ` David Bremner
2022-01-20 13:36 ` [PATCH v2 3/6] lib/date: factor out date range parsing David Bremner
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2022-01-20 13:36 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/6] lib/date: factor out date range parsing.
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
2022-01-20 13:36 ` [PATCH v2 1/6] test/search: add known broken tests for 'date' prefix David Bremner
2022-01-20 13:36 ` [PATCH v2 2/6] lib/parse-sexp: support zero argument date queries David Bremner
@ 2022-01-20 13:36 ` David Bremner
2022-01-20 13:36 ` [PATCH v2 4/6] lib/parse-sexp: support actual date queries David Bremner
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2022-01-20 13:36 UTC (permalink / raw)
To: notmuch
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 5db8882f..0c08fa15 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -379,5 +379,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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/6] lib/parse-sexp: support actual date queries.
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
` (2 preceding siblings ...)
2022-01-20 13:36 ` [PATCH v2 3/6] lib/date: factor out date range parsing David Bremner
@ 2022-01-20 13:36 ` David Bremner
2022-01-20 13:36 ` [PATCH v2 5/6] test/sexpr-search: add known broken tests for lastmod queries David Bremner
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2022-01-20 13:36 UTC (permalink / raw)
To: notmuch
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 | 48 ++++++++++++++++++++++++++++++++++-----
test/T081-sexpr-search.sh | 6 -----
2 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc
index f36d18a6..dbc3f89d 100644
--- a/lib/parse-sexp.cc
+++ b/lib/parse-sexp.cc
@@ -450,15 +450,52 @@ _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;
+
+ /* 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) {
+ 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;
+ }
+
+ _notmuch_database_log (notmuch, "unimplimented range prefix: '%s'\n", prefix->name);
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
}
@@ -557,9 +594,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..32b30493 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
@@ -829,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
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 5/6] test/sexpr-search: add known broken tests for lastmod queries
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
` (3 preceding siblings ...)
2022-01-20 13:36 ` [PATCH v2 4/6] lib/parse-sexp: support actual date queries David Bremner
@ 2022-01-20 13:36 ` David Bremner
2022-01-20 13:36 ` [PATCH v2 6/6] lib/parse-sexp: handle " David Bremner
2022-01-26 11:52 ` v2 add range operators to sexp queries David Bremner
6 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2022-01-20 13:36 UTC (permalink / raw)
To: notmuch
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 32b30493..4231dd38 100755
--- a/test/T081-sexpr-search.sh
+++ b/test/T081-sexpr-search.sh
@@ -831,6 +831,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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 6/6] lib/parse-sexp: handle lastmod queries.
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
` (4 preceding siblings ...)
2022-01-20 13:36 ` [PATCH v2 5/6] test/sexpr-search: add known broken tests for lastmod queries David Bremner
@ 2022-01-20 13:36 ` David Bremner
2022-01-26 11:52 ` v2 add range operators to sexp queries David Bremner
6 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2022-01-20 13:36 UTC (permalink / raw)
To: notmuch
This particular choice of converting strings to integers requires C++11.
---
lib/parse-sexp.cc | 25 +++++++++++++++++++++++++
test/T081-sexpr-search.sh | 10 ----------
2 files changed, 25 insertions(+), 10 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;
}
diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh
index 4231dd38..73f45041 100755
--- a/test/T081-sexpr-search.sh
+++ b/test/T081-sexpr-search.sh
@@ -832,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
@@ -846,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
@@ -854,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
@@ -863,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
@@ -872,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
@@ -881,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
@@ -890,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
@@ -899,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
@@ -908,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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: v2 add range operators to sexp queries
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
` (5 preceding siblings ...)
2022-01-20 13:36 ` [PATCH v2 6/6] lib/parse-sexp: handle " David Bremner
@ 2022-01-26 11:52 ` David Bremner
6 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2022-01-26 11:52 UTC (permalink / raw)
To: notmuch
David Bremner <david@tethera.net> writes:
> Changes since v1: move some date related changes (specifically the
> error message) from patch 6/6 back to patch 4/6. No change to the
> final tree (i.e. interdiff is empty)
series applied to master.
d
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-01-26 11:52 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 13:35 v2 add range operators to sexp queries David Bremner
2022-01-20 13:36 ` [PATCH v2 1/6] test/search: add known broken tests for 'date' prefix David Bremner
2022-01-20 13:36 ` [PATCH v2 2/6] lib/parse-sexp: support zero argument date queries David Bremner
2022-01-20 13:36 ` [PATCH v2 3/6] lib/date: factor out date range parsing David Bremner
2022-01-20 13:36 ` [PATCH v2 4/6] lib/parse-sexp: support actual date queries David Bremner
2022-01-20 13:36 ` [PATCH v2 5/6] test/sexpr-search: add known broken tests for lastmod queries David Bremner
2022-01-20 13:36 ` [PATCH v2 6/6] lib/parse-sexp: handle " David Bremner
2022-01-26 11:52 ` v2 add range operators to sexp queries David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).