From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ADbAHdYOJWGr4AAAgWs5BA (envelope-from ) for ; Tue, 24 Aug 2021 17:23:02 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id WBtkGdYOJWGDbgAAB5/wlQ (envelope-from ) for ; Tue, 24 Aug 2021 15:23:02 +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 140248AB9 for ; Tue, 24 Aug 2021 17:23:02 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2647026A78; Tue, 24 Aug 2021 11:21:28 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id AAB9426A25 for ; Tue, 24 Aug 2021 11:21:23 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id A2A365FD5C; Tue, 24 Aug 2021 11:21:23 -0400 (EDT) Received: (nullmailer pid 2942836 invoked by uid 1000); Tue, 24 Aug 2021 15:17:51 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 05/36] CLI/search+address: support sexpr queries Date: Tue, 24 Aug 2021 08:17:14 -0700 Message-Id: <20210824151745.2941868-6-david@tethera.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210824151745.2941868-1-david@tethera.net> References: <20210824151745.2941868-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: X3KUOEEQ2BRTHI3SBAFPEKQMIDQWO4MZ X-Message-ID-Hash: X3KUOEEQ2BRTHI3SBAFPEKQMIDQWO4MZ 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=1629818582; 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=f2d9JH7pDzWInFCuO0zJv+l8fGCkcXO3W9UsqmaOEcc=; b=tgknOeNbvKNeL3wSGWyK/kPHk3aH/Q/bbZ9KHCtn2+LQjlge0OeOA4Kx15hOgih9U9Knd0 GBGNpamP+DNHjKNvYoIms/sj+IEtUr9e8+klyGN5tXfDtHKU0GdOAS8jYpDGlCFSyYYz5u s4CvnyZbvmx3ibQ722tr6RnvDY2Oxmf78p7P+1KeBhfjMEbQFRzSqxTNAmQSPOCHCF07vl g8B/TdMGTTjC3VB5mbGaIuZyI7v2VBu0sw14dhpK5JEp3ED2ZwMXI2gv0+GHqm52Q1clNG n8bLUf5JRzrvwGJs2QhtHGTIvycvaW6cYs4ALvuosMMuJ8KsXwl6F1M4/iBzzg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629818582; a=rsa-sha256; cv=none; b=iBmWzcAnkV+c2OgTWGIT3hyLgd9rIlh9fGRuWsgxfnYPbIpGZMowNt0sPI8V+5xSCV7B2N OHPJ9XxSTfg5ApwXGnfbXNeS41IjWJAzxtyAlWrtr3yRUemt/dgB+5RssLeA+u1ThnV8/H wTEx15ROoQEJW5a1QkH5s4WNqggM4iFVIQwq4wt5esRyielwxjCQlsAFuDpZS/CdkFUvGd DrlyAE68Kf2zOFs4mmXJm7taq7Vsn5s0QGVznlZT32b8MGEiP0PyRRpo65o4Lbxqeh1BAt qBrJRr88Pow46YFDz0bIalj1XGdp4uMUhXoDCBdAXXZzJnFoyQJmNjAQN7718w== 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.00 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: 140248AB9 X-Spam-Score: -1.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: jQXJx+NZSfBH Initially support selection of query syntax in two subcommands to enable testing. --- notmuch-search.c | 13 +++++++++---- test/T080-search.sh | 7 +++++++ test/T095-address.sh | 7 +++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/notmuch-search.c b/notmuch-search.c index 375a247d..39d55bfe 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -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 = ¬much_format_version, .name = "format-version" }, { } }; diff --git a/test/T080-search.sh b/test/T080-search.sh index a3f0dead..9bda1eb9 100755 --- a/test/T080-search.sh +++ b/test/T080-search.sh @@ -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 diff --git a/test/T095-address.sh b/test/T095-address.sh index 817be538..8bb3627a 100755 --- a/test/T095-address.sh +++ b/test/T095-address.sh @@ -325,4 +325,11 @@ cat <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 -- 2.32.0