[PATCH v4 04/11] lib: Rearrange the exclude code in query.cc
authorMark Walters <markwalters1009@gmail.com>
Thu, 2 Feb 2012 17:43:32 +0000 (17:43 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:57 +0000 (09:43 -0800)
f9/cf25c7d9f62c24306fb3503e9c37e45b388637 [new file with mode: 0644]

diff --git a/f9/cf25c7d9f62c24306fb3503e9c37e45b388637 b/f9/cf25c7d9f62c24306fb3503e9c37e45b388637
new file mode 100644 (file)
index 0000000..42ce871
--- /dev/null
@@ -0,0 +1,148 @@
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 47E1C431FD7\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 09:43:06 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id gND7mW7nKRxt for <notmuch@notmuchmail.org>;\r
+       Thu,  2 Feb 2012 09:43:04 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id CE30F431FD4\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 09:43:01 -0800 (PST)\r
+Received: by mail-we0-f181.google.com with SMTP id b10so2324200wer.26\r
+       for <notmuch@notmuchmail.org>; Thu, 02 Feb 2012 09:43:01 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=IqeCmc2ELfjZkxjYdYxRGHL3vbcGmotc+462IZgK1tU=;\r
+       b=lZ5lpwIecXi3SDlQKlKu7TueNFtaHnjG7zQ3gAziwvzbiv2ctSp5Vv3j/5MZAenRg8\r
+       KFQM90G367bYOuFejb6SFZ1vMdpno/4Teubl2i4O6PZdTdckSU+rIoIDSDN1PkqJmPAu\r
+       Uk2gaZAb/y/XWL5YsRlah20DerxaIIkUr59qA=\r
+Received: by 10.216.131.215 with SMTP id m65mr1498378wei.54.1328204581497;\r
+       Thu, 02 Feb 2012 09:43:01 -0800 (PST)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223])     by mx.google.com with ESMTPS id\r
+ n5sm9123092wiw.7.2012.02.02.09.42.59  (version=TLSv1/SSLv3 cipher=OTHER);     Thu,\r
+ 02 Feb 2012 09:43:00 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org,\r
+       amdragon@MIT.EDU\r
+Subject: [PATCH v4 04/11] lib: Rearrange the exclude code in query.cc\r
+Date: Thu,  2 Feb 2012 17:43:32 +0000\r
+Message-Id: <1328204619-25046-4-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <874nv9rv79.fsf@qmul.ac.uk>\r
+References: <874nv9rv79.fsf@qmul.ac.uk>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 02 Feb 2012 17:43:06 -0000\r
+\r
+Slightly refactor the exclude code to give the callers access to the\r
+exclude query itself. There should be no functional change.\r
+---\r
+ lib/query.cc |   29 +++++++++++++++++++----------\r
+ 1 files changed, 19 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 0b36602..c25b301 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -122,12 +122,15 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)\r
+     return 0;\r
+ }\r
\r
+-/* Return a query that does not match messages with the excluded tags\r
+- * registered with the query.  Any tags that explicitly appear in\r
+- * xquery will not be excluded. */\r
++/* Return a query that matches messages with the excluded tags\r
++ * registered with query.  Any tags that explicitly appear in xquery\r
++ * will not be excluded. The caller of this function has to combine\r
++ * the returned query appropriately.*/\r
+ static Xapian::Query\r
+ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
+ {\r
++    Xapian::Query exclude_query = Xapian::Query::MatchNothing;\r
++\r
+     for (notmuch_string_node_t *term = query->exclude_terms->head; term;\r
+        term = term->next) {\r
+       Xapian::TermIterator it = xquery.get_terms_begin ();\r
+@@ -137,10 +140,10 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
+               break;\r
+       }\r
+       if (it == end)\r
+-          xquery = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+-                                  xquery, Xapian::Query (term->string));\r
++          exclude_query = Xapian::Query (Xapian::Query::OP_OR,\r
++                                  exclude_query, Xapian::Query (term->string));\r
+     }\r
+-    return xquery;\r
++    return exclude_query;\r
+ }\r
\r
+ notmuch_messages_t *\r
+@@ -168,7 +171,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+       Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
+                                                  _find_prefix ("type"),\r
+                                                  "mail"));\r
+-      Xapian::Query string_query, final_query;\r
++      Xapian::Query string_query, final_query, exclude_query;\r
+       Xapian::MSet mset;\r
+       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+                             Xapian::QueryParser::FLAG_PHRASE |\r
+@@ -188,7 +191,10 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+                                        mail_query, string_query);\r
+       }\r
\r
+-      final_query = _notmuch_exclude_tags (query, final_query);\r
++      exclude_query = _notmuch_exclude_tags (query, final_query);\r
++\r
++      final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
++                                       final_query, exclude_query);\r
\r
+       enquire.set_weighting_scheme (Xapian::BoolWeight());\r
\r
+@@ -449,7 +455,7 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+       Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
+                                                  _find_prefix ("type"),\r
+                                                  "mail"));\r
+-      Xapian::Query string_query, final_query;\r
++      Xapian::Query string_query, final_query, exclude_query;\r
+       Xapian::MSet mset;\r
+       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+                             Xapian::QueryParser::FLAG_PHRASE |\r
+@@ -469,7 +475,10 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+                                        mail_query, string_query);\r
+       }\r
\r
+-      final_query = _notmuch_exclude_tags (query, final_query);\r
++      exclude_query = _notmuch_exclude_tags (query, final_query);\r
++\r
++      final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
++                                       final_query, exclude_query);\r
\r
+       enquire.set_weighting_scheme(Xapian::BoolWeight());\r
+       enquire.set_docid_order(Xapian::Enquire::ASCENDING);\r
+-- \r
+1.7.2.3\r
+\r