From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id sLs+LeqU82CiGAAAgWs5BA (envelope-from ) for ; Sun, 18 Jul 2021 04:41:46 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id cFn5KOqU82C3XgAA1q6Kng (envelope-from ) for ; Sun, 18 Jul 2021 02:41:46 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 37E291C245 for ; Sun, 18 Jul 2021 04:41:46 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 84C1929A6D; Sat, 17 Jul 2021 22:41:11 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id A0D7029114 for ; Sat, 17 Jul 2021 22:40:42 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 7A16C5FD21; Sat, 17 Jul 2021 22:40:42 -0400 (EDT) Received: (nullmailer pid 3853967 invoked by uid 1000); Sun, 18 Jul 2021 02:40:27 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 23/25] lib/parse-sexp: support thread subqueries. Date: Sat, 17 Jul 2021 23:40:19 -0300 Message-Id: <20210718024021.3850340-24-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210718024021.3850340-1-david@tethera.net> References: <20210718024021.3850340-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: FTLNPSY7CVACIFQLDW4M432TJL7QEY4J X-Message-ID-Hash: FTLNPSY7CVACIFQLDW4M432TJL7QEY4J 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=1626576106; 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=OyARGwvkIp5KUaZHUfukzVqwNEBLlKrLyhPCm0Oy8GY=; b=fuR9yAS7VrdLUx6JfVo7VZJQROgkGJDwp5p870dlogeE40CcGf3VWJS49aPiSB+IsHvzr3 rKmaWS13ki8xjFxIqWEualSpi3PwULdPognPVxRySrzJEvmi66K8u1XHwRUVhs3e8Udbna YxW8jYYTx8qPH4MUbgpOeZK1LvlQpO7rcZuHo9b4JttPxC13KfNylBEaEILo+OLM+Qn+dp Cd5KiboPGDW3LUDTFrPjK4uIoR03CjhZdXVTxMhozl/REdAP6kc86sWJiwpxPqCnA0nPco wmBxPx1iciBeuoaMSpRtsxXkuAFWVCdkY+HZvkv/yqBwhvMB3OU8q9z/GyX6Vg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626576106; a=rsa-sha256; cv=none; b=W8aiG0KbZPO5REe7DC8Wd9wph3JdSZxHDEtw9X2UeWcoONlxPYutV3jmXWru8oHXg9Johg 4MlfIpHqpM2JQqUZ+k8UCW2NuPQgs1uHO/NNkFBYTnxtrRiU8T7sCgKQugtBt+tLCHZXLV xb+Wrnb6E+CAhOB0SMH89Sk9tNbgzN7R++JOPyBOqGDKvRgvm5jHCkMCYcys6Cx9iCdBsw rQf4pOZaG0XwhVjB+CbdMFmiSc+FwJwcGiol7GTlKU7kf35i2uuq41PPzoAgSdLzRxuOWQ 7nMLST6H9y5Z+4otbsTrCXlfYTT2nbTcP6d7rNclJG+8u8RAjSLGNEkKsX7pRQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.05 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 37E291C245 X-Spam-Score: -1.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: XE4P271UdjW5 This essentially mimics the ThreadFieldProcessor code, but generating the notmuch_query_t via the new notmuch_query_from_sexp using a subtree of the already parsed s-expression. --- lib/parse-sexp.cc | 27 +++++++++++++++++++++++---- test/T081-sexpr-search.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index cfd503d9..df3629af 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -11,9 +11,10 @@ typedef struct { } _sexp_op_t; typedef enum { - SEXP_FLAG_NONE = 0, - SEXP_FLAG_WILDCARD = 1 << 0, - SEXP_FLAG_REGEXP = 1 << 1, + SEXP_FLAG_NONE = 0, + SEXP_FLAG_WILDCARD = 1 << 0, + SEXP_FLAG_REGEXP = 1 << 1, + SEXP_FLAG_THREAD_MATCH = 1 << 2, } _sexp_flag_t; /* @@ -63,7 +64,7 @@ static _sexp_field_t fields[] = { "query", Xapian::Query::OP_INVALID, SEXP_FLAG_NONE }, { "subject", Xapian::Query::OP_PHRASE, SEXP_FLAG_REGEXP }, { "tag", Xapian::Query::OP_AND, SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEXP }, - { "thread", Xapian::Query::OP_OR, SEXP_FLAG_REGEXP }, + { "thread", Xapian::Query::OP_OR, SEXP_FLAG_REGEXP | SEXP_FLAG_THREAD_MATCH }, { "to", Xapian::Query::OP_PHRASE, SEXP_FLAG_NONE }, { } }; @@ -78,6 +79,7 @@ static _sexp_keyword_t keywords[] = { "any", SEXP_FLAG_WILDCARD }, { "*", SEXP_FLAG_WILDCARD }, { "rx", SEXP_FLAG_REGEXP }, + { "match", SEXP_FLAG_THREAD_MATCH }, { } }; @@ -313,6 +315,23 @@ _notmuch_sexp_to_xapian_query (notmuch_database_t *notmuch, const sexp_t *sx, Xa return _notmuch_regexp_to_query (notmuch, Xapian::BAD_VALUENO, field->name, rest->val, output, msg); } + } else if (flags & SEXP_FLAG_THREAD_MATCH) { + if (! rest) { + _notmuch_database_log (notmuch, "missing subquery\n"); + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } else { + notmuch_query_t *query; + std::string msg; + + status = _notmuch_query_from_sexpr (notmuch, rest, query); + if (status) + return status; + status = _notmuch_query_expand_to_threads (query, output, msg); + if (status) { + _notmuch_database_log (notmuch, "error expanding query %s\n", msg.c_str ()); + } + return status; + } } else { return _sexp_combine_field (term_prefix, field->xapian_op, rest, output); diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 281a9bf7..f0a7efb0 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -436,4 +436,39 @@ notmuch search --output=threads '*' | grep '7$' > EXPECTED notmuch search --output=threads --query-syntax=sexp '(thread :rx 7$)' > OUTPUT test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "Basic query that matches no messages" +count=$(notmuch count from:keithp and to:keithp) +test_expect_equal 0 "$count" + +test_begin_subtest "Same query against threads" +notmuch search --query-syntax=sexp '(and (thread :match (from keithp)) (thread :match (to keithp)))' \ + | notmuch_search_sanitize > OUTPUT +cat< EXPECTED +thread:XXX 2009-11-18 [7/7] Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread) +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "Mix thread and non-threads query" +notmuch search --query-syntax=sexp '(and (thread :match keithp) (to keithp))' | notmuch_search_sanitize > OUTPUT +cat< EXPECTED +thread:XXX 2009-11-18 [1/7] Lars Kellogg-Stedman| Mikhail Gusarov, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread) +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "Compound subquery" +notmuch search --query-syntax=sexp '(and (thread :match (and (from keithp) (date 2009))) (thread :match (to keithp)))' \ + | notmuch_search_sanitize > OUTPUT +cat< EXPECTED +thread:XXX 2009-11-18 [7/7] Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread) +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "missing subquery" +notmuch search --query-syntax=sexp '(thread :match)' 1>OUTPUT 2>&1 +cat< EXPECTED +notmuch search: Syntax error in query +missing subquery +EOF +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.30.2