]> git.cworth.org Git - notmuch/commitdiff
CLI/search+address: support sexpr queries
authorDavid Bremner <david@tethera.net>
Tue, 24 Aug 2021 15:17:14 +0000 (08:17 -0700)
committerDavid Bremner <david@tethera.net>
Sun, 5 Sep 2021 00:07:19 +0000 (17:07 -0700)
Initially support selection of query syntax in two subcommands to
enable testing.

notmuch-search.c
test/T080-search.sh
test/T095-address.sh

index 375a247dca58a963189ed81aa8407a967b6e680e..39d55bfeb25e33add37d2d017f36551d5ec2f842 100644 (file)
@@ -56,6 +56,7 @@ typedef struct {
     int format_sel;
     sprinter_t *format;
     int exclude;
+    int query_syntax;
     notmuch_query_t *query;
     int sort;
     int output;
@@ -719,11 +720,10 @@ _notmuch_search_prepare (search_context_t *ctx, int argc, char *argv[])
        return EXIT_FAILURE;
     }
 
-    ctx->query = notmuch_query_create (ctx->notmuch, query_str);
-    if (ctx->query == NULL) {
-       fprintf (stderr, "Out of memory\n");
+    if (print_status_database ("notmuch search", ctx->notmuch,
+                              notmuch_query_create_with_syntax (ctx->notmuch, query_str,
+                                                                ctx->query_syntax, &ctx->query)))
        return EXIT_FAILURE;
-    }
 
     notmuch_query_set_sort (ctx->query, ctx->sort);
 
@@ -769,6 +769,7 @@ static search_context_t search_context = {
     .format_sel = NOTMUCH_FORMAT_TEXT,
     .exclude = NOTMUCH_EXCLUDE_TRUE,
     .sort = NOTMUCH_SORT_NEWEST_FIRST,
+    .query_syntax = NOTMUCH_QUERY_SYNTAX_XAPIAN,
     .output = 0,
     .offset = 0,
     .limit = -1, /* unlimited */
@@ -787,6 +788,10 @@ static const notmuch_opt_desc_t common_options[] = {
                                  { "text", NOTMUCH_FORMAT_TEXT },
                                  { "text0", NOTMUCH_FORMAT_TEXT0 },
                                  { 0, 0 } } },
+    { .opt_keyword = &search_context.query_syntax, .name = "query", .keywords =
+         (notmuch_keyword_t []){ { "infix", NOTMUCH_QUERY_SYNTAX_XAPIAN },
+                                 { "sexp", NOTMUCH_QUERY_SYNTAX_SEXP },
+                                 { 0, 0 } } },
     { .opt_int = &notmuch_format_version, .name = "format-version" },
     { }
 };
index a3f0dead1420239fd654c89ea04531d1ee141729..9bda1eb9f4e4597eb0f64cad3272c0260941dac0 100755 (executable)
@@ -189,4 +189,11 @@ test_begin_subtest "parts do not have adjacent term positions"
 output=$(notmuch search id:termpos and '"c x"')
 test_expect_equal "$output" ""
 
+if [[ NOTMUCH_HAVE_SFSEXP = 1 ]]; then
+    test_begin_subtest "sexpr query: all messages"
+    notmuch search '*' > EXPECTED
+    notmuch search --query=sexp '()' > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+fi
+
 test_done
index 817be5380a45d9a98a7a6bbd2031269575dd13ba..8bb3627ac1f0e39307d134548b4a2122ddcba51d 100755 (executable)
@@ -325,4 +325,11 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+if [[ NOTMUCH_HAVE_SFSEXP = 1 ]]; then
+    test_begin_subtest "sexpr query: all messages"
+    notmuch address '*' > EXPECTED
+    notmuch address --query=sexp '()' > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+fi
+
 test_done