From ade432063aad63ae54e98fb31318840c5637b202 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Thu, 1 Mar 2012 22:30:36 +0000 Subject: [PATCH] [Patch v7 04/13] lib: Rearrange the exclude code in query.cc --- 75/7c60cb7f5fcaec304d4476aacc078a9f89d044 | 159 ++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 75/7c60cb7f5fcaec304d4476aacc078a9f89d044 diff --git a/75/7c60cb7f5fcaec304d4476aacc078a9f89d044 b/75/7c60cb7f5fcaec304d4476aacc078a9f89d044 new file mode 100644 index 000000000..db4425136 --- /dev/null +++ b/75/7c60cb7f5fcaec304d4476aacc078a9f89d044 @@ -0,0 +1,159 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id B3766431FAE + for ; Thu, 1 Mar 2012 14:29:17 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id uaPi3Ycni+k0 for ; + Thu, 1 Mar 2012 14:29:16 -0800 (PST) +Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com + [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + B71D5431FD9 for ; Thu, 1 Mar 2012 14:29:15 -0800 + (PST) +Received: by mail-ww0-f45.google.com with SMTP id dt12so108365wgb.2 + for ; Thu, 01 Mar 2012 14:29:15 -0800 (PST) +Received-SPF: pass (google.com: domain of markwalters1009@gmail.com designates + 10.216.135.37 as permitted sender) client-ip=10.216.135.37; +Authentication-Results: mr.google.com; spf=pass (google.com: domain of + markwalters1009@gmail.com designates 10.216.135.37 as permitted + sender) smtp.mail=markwalters1009@gmail.com; + dkim=pass header.i=markwalters1009@gmail.com +Received: from mr.google.com ([10.216.135.37]) + by 10.216.135.37 with SMTP id t37mr3727875wei.44.1330640955574 + (num_hops = 1); Thu, 01 Mar 2012 14:29:15 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=IqeCmc2ELfjZkxjYdYxRGHL3vbcGmotc+462IZgK1tU=; + b=IqYEifET17vCOTmYGu68qoZtqL0yV2DZF5ETVWGMSnWjM+0ap/Dlcv0Ve29z4IEEqo + bxUzfgxT9qASfsshBbBdYjoDucd1RCKo9GzpbWs5MGlSpIbnNR48Wq5kFNG4kgC6jibK + nVxkd+SSD5K7QBZbpR+zU0yJYbp8kvEuKSRV2mEYPd11nrdH9GR6aYBFzEWeruPk8vDo + b0ah/XQgUXQhoU0xD02fU7tJuJOwwqnC7DtUxCbTH27ZnefZSIAwWAa2oL1dEVmqyW9+ + wWkD94niUwgJKXeQk0M09TbzeJhSg0wVIA56LXdb4TeojcSt6QxWBcXC/zXVivSr/Yki + GYxw== +Received: by 10.216.135.37 with SMTP id t37mr2993837wei.44.1330640955495; + Thu, 01 Mar 2012 14:29:15 -0800 (PST) +Received: from localhost (94-192-233-223.zone6.bethere.co.uk. + [94.192.233.223]) by mx.google.com with ESMTPS id + k6sm29802209wiy.7.2012.03.01.14.29.13 (version=TLSv1/SSLv3 cipher=OTHER); + Thu, 01 Mar 2012 14:29:14 -0800 (PST) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [Patch v7 04/13] lib: Rearrange the exclude code in query.cc +Date: Thu, 1 Mar 2012 22:30:36 +0000 +Message-Id: <1330641045-27416-5-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.2.3 +In-Reply-To: <1330641045-27416-1-git-send-email-markwalters1009@gmail.com> +References: <1330641045-27416-1-git-send-email-markwalters1009@gmail.com> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 01 Mar 2012 22:29:18 -0000 + +Slightly refactor the exclude code to give the callers access to the +exclude query itself. There should be no functional change. +--- + lib/query.cc | 29 +++++++++++++++++++---------- + 1 files changed, 19 insertions(+), 10 deletions(-) + +diff --git a/lib/query.cc b/lib/query.cc +index 0b36602..c25b301 100644 +--- a/lib/query.cc ++++ b/lib/query.cc +@@ -122,12 +122,15 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages) + return 0; + } + +-/* Return a query that does not match messages with the excluded tags +- * registered with the query. Any tags that explicitly appear in +- * xquery will not be excluded. */ ++/* Return a query that matches messages with the excluded tags ++ * registered with query. Any tags that explicitly appear in xquery ++ * will not be excluded. The caller of this function has to combine ++ * the returned query appropriately.*/ + static Xapian::Query + _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery) + { ++ Xapian::Query exclude_query = Xapian::Query::MatchNothing; ++ + for (notmuch_string_node_t *term = query->exclude_terms->head; term; + term = term->next) { + Xapian::TermIterator it = xquery.get_terms_begin (); +@@ -137,10 +140,10 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery) + break; + } + if (it == end) +- xquery = Xapian::Query (Xapian::Query::OP_AND_NOT, +- xquery, Xapian::Query (term->string)); ++ exclude_query = Xapian::Query (Xapian::Query::OP_OR, ++ exclude_query, Xapian::Query (term->string)); + } +- return xquery; ++ return exclude_query; + } + + notmuch_messages_t * +@@ -168,7 +171,7 @@ notmuch_query_search_messages (notmuch_query_t *query) + Xapian::Query mail_query (talloc_asprintf (query, "%s%s", + _find_prefix ("type"), + "mail")); +- Xapian::Query string_query, final_query; ++ Xapian::Query string_query, final_query, exclude_query; + Xapian::MSet mset; + unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN | + Xapian::QueryParser::FLAG_PHRASE | +@@ -188,7 +191,10 @@ notmuch_query_search_messages (notmuch_query_t *query) + mail_query, string_query); + } + +- final_query = _notmuch_exclude_tags (query, final_query); ++ exclude_query = _notmuch_exclude_tags (query, final_query); ++ ++ final_query = Xapian::Query (Xapian::Query::OP_AND_NOT, ++ final_query, exclude_query); + + enquire.set_weighting_scheme (Xapian::BoolWeight()); + +@@ -449,7 +455,7 @@ notmuch_query_count_messages (notmuch_query_t *query) + Xapian::Query mail_query (talloc_asprintf (query, "%s%s", + _find_prefix ("type"), + "mail")); +- Xapian::Query string_query, final_query; ++ Xapian::Query string_query, final_query, exclude_query; + Xapian::MSet mset; + unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN | + Xapian::QueryParser::FLAG_PHRASE | +@@ -469,7 +475,10 @@ notmuch_query_count_messages (notmuch_query_t *query) + mail_query, string_query); + } + +- final_query = _notmuch_exclude_tags (query, final_query); ++ exclude_query = _notmuch_exclude_tags (query, final_query); ++ ++ final_query = Xapian::Query (Xapian::Query::OP_AND_NOT, ++ final_query, exclude_query); + + enquire.set_weighting_scheme(Xapian::BoolWeight()); + enquire.set_docid_order(Xapian::Enquire::ASCENDING); +-- +1.7.2.3 + -- 2.26.2