From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QGdAHdop7mC8egAAgWs5BA (envelope-from ) for ; Wed, 14 Jul 2021 02:03:38 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id UC0AGdop7mDQWgAAB5/wlQ (envelope-from ) for ; Wed, 14 Jul 2021 00:03:38 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1FCE1ADE4 for ; Wed, 14 Jul 2021 02:03:38 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 1DBDF2910B; Tue, 13 Jul 2021 20:03:10 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 05A8A29083 for ; Tue, 13 Jul 2021 20:02:50 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id B7F835FD21; Tue, 13 Jul 2021 20:02:49 -0400 (EDT) Received: (nullmailer pid 804655 invoked by uid 1000); Wed, 14 Jul 2021 00:02:42 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 04/11] CLI/search+address: support sexpr queries Date: Tue, 13 Jul 2021 21:02:32 -0300 Message-Id: <20210714000239.804384-5-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210714000239.804384-1-david@tethera.net> References: <20210714000239.804384-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: OL6ISRK5XTA5QXYNCZMH3S2QTTPNYE6P X-Message-ID-Hash: OL6ISRK5XTA5QXYNCZMH3S2QTTPNYE6P X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1626221018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+e3RTZpWHlUPEbsiTwJqCUM9W5Yce9qiQVxstngDwLU=; b=W+TZsOmPXT8NkFjAYujowR1ELCLpGBXO4sdmRlG7HpXEX2ELcpn4GgNbsS0M03UnXb5gC3 ctgjsEtPI8XzHDSpSKVR1sB38nJA8Z7/FuIfKf84V+KeTNHbdtg3u5FSnVwkI76FoCKc08 AcCEgK8dlMcOnGGQpCxcedHqcAIGiAdD8Hy91ijFxEusA7BW9TEWAJyw4xmi/pJv09v0g7 crIg417qUX3W1hFfr6w2f6o9FPo6C5mcWOhuIpA/7XbIkk0fuSipByZPwd6/kVlnl2euDV s0LVvUqVgm1+XeIvwoT4qw9hqdOY9oium/AWRpRahiJTxpqePO9ANCeRR4NsTQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626221018; a=rsa-sha256; cv=none; b=A50fJST04URmtckHpynmZsl4DOoBT707wiCYoJwn/3Gtzqx6+VC7nCtAJs8RsyWkMaJ3Wa cXETqewh1mZTPQiB4pGL+Rh6B9tx5leN3/BkH3cr1EiUnf4rnyg3cTN9fm4beK0bpRkPjZ EZJzLxhRDehe77Oggn3Aww6hC6trcH5I1IZ4f/cJJUfJogdkXf7kiJ4kxLQHTHLygxRd+B nJ7wajmHPxhANjKeVORLEMZe4cmFyQq9PUAZ2ZOZT7T3s3Cj4gLcTqXBmvLRqfc7uGVKPQ 3jYmTCQ6uQYyPse5z8KamnL6i3YFkp/spDtY54MPRR66yLuqyntCL0IbuA0zHw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.08 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 1FCE1ADE4 X-Spam-Score: -1.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: s4Hu9f/RL8ye Initially support selection of query syntax in two subcommands to enable testing. --- notmuch-search.c | 16 +++++++++++++++- test/T080-search.sh | 5 +++++ test/T095-address.sh | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/notmuch-search.c b/notmuch-search.c index 244817a9..fd25a414 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -43,6 +43,11 @@ typedef enum { DEDUP_ADDRESS, } dedup_t; +typedef enum { + QUERY_SYNTAX_XAPIAN, + QUERY_SYNTAX_SEXP +} query_syntax_t; + typedef enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT, @@ -56,6 +61,7 @@ typedef struct { int format_sel; sprinter_t *format; int exclude; + int query_syntax; notmuch_query_t *query; int sort; int output; @@ -721,7 +727,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_syntax == QUERY_SYNTAX_SEXP) + ctx->query = notmuch_query_create_sexpr (ctx->notmuch, query_str); + else + ctx->query = notmuch_query_create (ctx->notmuch, query_str); if (ctx->query == NULL) { fprintf (stderr, "Out of memory\n"); return EXIT_FAILURE; @@ -771,6 +780,7 @@ static search_context_t search_context = { .format_sel = NOTMUCH_FORMAT_TEXT, .exclude = NOTMUCH_EXCLUDE_TRUE, .sort = NOTMUCH_SORT_NEWEST_FIRST, + .query_syntax = QUERY_SYNTAX_XAPIAN, .output = 0, .offset = 0, .limit = -1, /* unlimited */ @@ -789,6 +799,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-syntax", .keywords = + (notmuch_keyword_t []){ { "xapian", QUERY_SYNTAX_XAPIAN }, + { "sexp", QUERY_SYNTAX_SEXP }, + { 0, 0 } } }, { .opt_int = ¬much_format_version, .name = "format-version" }, { } }; diff --git a/test/T080-search.sh b/test/T080-search.sh index a3f0dead..966e772a 100755 --- a/test/T080-search.sh +++ b/test/T080-search.sh @@ -189,4 +189,9 @@ test_begin_subtest "parts do not have adjacent term positions" output=$(notmuch search id:termpos and '"c x"') test_expect_equal "$output" "" +test_begin_subtest "sexpr query: all messages" +notmuch search '*' > EXPECTED +notmuch search --query-syntax=sexp '()' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + test_done diff --git a/test/T095-address.sh b/test/T095-address.sh index 817be538..adf0b307 100755 --- a/test/T095-address.sh +++ b/test/T095-address.sh @@ -325,4 +325,9 @@ cat <EXPECTED EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "sexpr query: all messages" +notmuch address '*' > EXPECTED +notmuch address --query-syntax=sexp '()' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.30.2