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 mNRjB4BVFWFRMQEAgWs5BA (envelope-from ) for ; Thu, 12 Aug 2021 19:08:16 +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 gIQMA4BVFWFyUwAAB5/wlQ (envelope-from ) for ; Thu, 12 Aug 2021 17:08:16 +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 9F35EBA2A for ; Thu, 12 Aug 2021 19:08:15 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id B507E291FA; Thu, 12 Aug 2021 13:07:59 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 2252D291ED for ; Thu, 12 Aug 2021 13:07:52 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 059EE5FD5C; Thu, 12 Aug 2021 13:07:51 -0400 (EDT) Received: (nullmailer pid 1348757 invoked by uid 1000); Thu, 12 Aug 2021 17:07:43 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 17/31] lib/query: generalize exclude handling to s-expression queries Date: Thu, 12 Aug 2021 10:07:14 -0700 Message-Id: <20210812170728.1348333-18-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812170728.1348333-1-david@tethera.net> References: <20210812170728.1348333-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: IWIKSQTFUNMJMB2QOHFO6LJTP5ZU3JC7 X-Message-ID-Hash: IWIKSQTFUNMJMB2QOHFO6LJTP5ZU3JC7 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=1628788095; 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=rc+3fHDgv0oS6eG+K/42V/O/tl0n9oj3fUnjuvDG3h8=; b=tpH1js7WfwHcVRUicm6p/T3I6067rLJfCrLH7/rhAn32DQdZT6fLy/C52wLVnSm6AcyZwG 7Hy+uIDH9A7wGFMdQ4AepWxY1XJb1MP2iqACrtelF9s3usRqG9oD37petce8fQMweciqm1 viZlOR1IjyrQ+NGxXRgbz5li0m3fIsYF93phioL/MzS3nSsmHS4VmWiZcEQt6N9ILp/Oht f3xI9LV2ZBds1tvRJqi7GQLroRHWp23rXl7tE0r7rXVnsP68MjjsHCQHWF4JYvxfeCWTht cPCBbMKhubEjyBVV3WP5fhr0vFrpZ5ImujftIqYKfKbkd5LsgqVeOhfRtGcOCQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628788095; a=rsa-sha256; cv=none; b=YrgoGU1eC3zCkCsJ+WScDtQ1HxvxIQ8XWMmjiERmjCDmtbIT7U2cRy/dspdvIoUYxrJ3iQ bhSzq/MHB+Pqeo98PDiDwImWwfTTc6J+Zczj95/GCjMBGXpVNZAMRK0wBf/VxKHAJrXTpm dQHB1b1b3J3jsxOBaFI2u7f4lm/cJMen+Cu1VHKvyte7HXo6vVR0m3Ix3mI8hC2Dc1KU/5 f2lDbBtmQLw7J/x7Whm1kwsw3J8tcKIaIsRufcYN0N7+Pm0lAIHoJVdSuIIMMtEFY+KsQR YTNc1cnEHqLRnwdLkcXlYLICIC3PNEwjC5zIvHbchI2AOeG1xVgsVfuo+2vFPA== 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: 0.48 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: 9F35EBA2A X-Spam-Score: 0.48 X-Migadu-Scanner: scn1.migadu.com X-TUID: QUG/9ZJlps7c In fact most of the code path is in common, only the caching of terms in the query needs to be added for s-expression queries. --- lib/query.cc | 34 ++++++++++++++++++++++----------- test/T081-sexpr-search.sh | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/lib/query.cc b/lib/query.cc index 435f7229..56f90e1c 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -165,6 +165,19 @@ notmuch_query_create_with_syntax (notmuch_database_t *notmuch, return NOTMUCH_STATUS_SUCCESS; } +static void +_notmuch_query_cache_terms (notmuch_query_t *query) +{ + /* Xapian doesn't support skip_to on terms from a query since + * they are unordered, so cache a copy of all terms in + * something searchable. + */ + + for (Xapian::TermIterator t = query->xapian_query.get_terms_begin (); + t != query->xapian_query.get_terms_end (); ++t) + query->terms.insert (*t); +} + static notmuch_status_t _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) { @@ -173,15 +186,7 @@ _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) query->notmuch->query_parser-> parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS); - /* Xapian doesn't support skip_to on terms from a query since - * they are unordered, so cache a copy of all terms in - * something searchable. - */ - - for (Xapian::TermIterator t = query->xapian_query.get_terms_begin (); - t != query->xapian_query.get_terms_end (); ++t) - query->terms.insert (*t); - + _notmuch_query_cache_terms (query); query->parsed = true; } catch (const Xapian::Error &error) { @@ -203,11 +208,18 @@ _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) static notmuch_status_t _notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query) { + notmuch_status_t status; + if (query->parsed) return NOTMUCH_STATUS_SUCCESS; - return _notmuch_sexp_string_to_xapian_query (query->notmuch, query->query_string, - query->xapian_query); + status = _notmuch_sexp_string_to_xapian_query (query->notmuch, query->query_string, + query->xapian_query); + if (status) + return status; + + _notmuch_query_cache_terms (query); + return NOTMUCH_STATUS_SUCCESS; } static notmuch_status_t diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 44cb681f..be243fc0 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -525,4 +525,44 @@ notmuch search: Syntax error in query EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "Search, exclude \"deleted\" messages from search" +notmuch config set search.exclude_tags deleted +generate_message '[subject]="Not deleted"' +not_deleted_id=$gen_msg_id +generate_message '[subject]="Deleted"' +notmuch new > /dev/null +notmuch tag +deleted id:$gen_msg_id +deleted_id=$gen_msg_id +output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)" + +test_begin_subtest "Search, exclude \"deleted\" messages from message search --exclude=false" +output=$(notmuch search --query=sexp --exclude=false --output=messages '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "id:$not_deleted_id +id:$deleted_id" + +test_begin_subtest "Search, exclude \"deleted\" messages from search, overridden" +notmuch search --query=sexp '(and (subject deleted) (tag deleted))' | notmuch_search_sanitize > OUTPUT +cat < EXPECTED +thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Deleted (deleted inbox unread) +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "Search, exclude \"deleted\" messages from threads" +add_message '[subject]="Not deleted reply"' '[in-reply-to]="<$gen_msg_id>"' +output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) +thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)" + +test_begin_subtest "Search, don't exclude \"deleted\" messages when --exclude=flag specified" +output=$(notmuch search --query=sexp --exclude=flag '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) +thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Deleted (deleted inbox unread)" + +test_begin_subtest "Search, don't exclude \"deleted\" messages from search if not configured" +notmuch config set search.exclude_tags +output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) +thread:XXX 2001-01-05 [2/2] Notmuch Test Suite; Deleted (deleted inbox unread)" + test_done -- 2.30.2