[Patch v7 06/13] lib: Add the exclude flag to notmuch_query_search_threads
authorMark Walters <markwalters1009@gmail.com>
Thu, 1 Mar 2012 22:30:38 +0000 (22:30 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:09 +0000 (09:45 -0800)
be/4207c44fd32f392aa958131d5a91c91048246b [new file with mode: 0644]

diff --git a/be/4207c44fd32f392aa958131d5a91c91048246b b/be/4207c44fd32f392aa958131d5a91c91048246b
new file mode 100644 (file)
index 0000000..905efa0
--- /dev/null
@@ -0,0 +1,211 @@
+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 9C2CF431FDE\r
+       for <notmuch@notmuchmail.org>; Thu,  1 Mar 2012 14:29:47 -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 sgKWmm+OpHX2 for <notmuch@notmuchmail.org>;\r
+       Thu,  1 Mar 2012 14:29:45 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+       [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id A796E429E29\r
+       for <notmuch@notmuchmail.org>; Thu,  1 Mar 2012 14:29:31 -0800 (PST)\r
+Received: by mail-wi0-f181.google.com with SMTP id o1so305757wic.26\r
+       for <notmuch@notmuchmail.org>; Thu, 01 Mar 2012 14:29:31 -0800 (PST)\r
+Received-SPF: pass (google.com: domain of markwalters1009@gmail.com designates\r
+       10.180.107.99 as permitted sender) client-ip=10.180.107.99; \r
+Authentication-Results: mr.google.com; spf=pass (google.com: domain of\r
+       markwalters1009@gmail.com designates 10.180.107.99 as permitted\r
+       sender) smtp.mail=markwalters1009@gmail.com;\r
+       dkim=pass header.i=markwalters1009@gmail.com\r
+Received: from mr.google.com ([10.180.107.99])\r
+       by 10.180.107.99 with SMTP id hb3mr15031246wib.5.1330640971521\r
+       (num_hops = 1); Thu, 01 Mar 2012 14:29:31 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=BsaS5Zpnoh6DatNKWnhrJrtCDw2ujgE0cyPqM93aJfM=;\r
+       b=CEreg372lEs2PAzL+R9mmKQ3RusNRyaXS/8qqB6//fWzlv+esozfzP5IgeE0VRyet/\r
+       hJqAvle8iBfc+z4i3NPAdU8Cizy5t1sRDXNeo/bksGNH1pILkYDcWULKL+lKnM2ngxXe\r
+       QsUVvNyYUiDSCjdPSESdRViFM3p1L8PnWm5YjeJOoh5oJnLk3UXEJIrfsTFnmPYA+gJK\r
+       VMpJ+IDOsRXtCCvzNTj9DCFD3V6zrHsZhJm8mqbggh4tKl+JofsEKTdcvrQY7siGeiP8\r
+       9ZE6wtuOoWfoWrzF2BfmGZVrabu4NVPXTP2ut3aPMzikLn+1TuA31Yt9wX3CypPGlBFP\r
+       EmTQ==\r
+Received: by 10.180.107.99 with SMTP id hb3mr12083013wib.5.1330640971468;\r
+       Thu, 01 Mar 2012 14:29:31 -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
+ hn8sm10961838wib.11.2012.03.01.14.29.27       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 01 Mar 2012 14:29:30 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v7 06/13] lib: Add the exclude flag to\r
+       notmuch_query_search_threads\r
+Date: Thu,  1 Mar 2012 22:30:38 +0000\r
+Message-Id: <1330641045-27416-7-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1330641045-27416-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1330641045-27416-1-git-send-email-markwalters1009@gmail.com>\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, 01 Mar 2012 22:29:48 -0000\r
+\r
+Add the NOTMUCH_MESSAGE_FLAG_EXCLUDED flag to\r
+notmuch_query_search_threads. Implemented by inspecting the tags\r
+directly in _notmuch_thread_create/_thread_add_message rather than as\r
+a Xapian query for speed reasons.\r
+\r
+Note notmuch_thread_get_matched_messages now returns the number of\r
+non-excluded matching messages. This API is not totally desirable but\r
+fixing it means breaking binary compatibility so we delay that.\r
+---\r
+ lib/notmuch-private.h |    7 +++++--\r
+ lib/notmuch.h         |    6 ++++--\r
+ lib/query.cc          |    1 +\r
+ lib/thread.cc         |   18 +++++++++++++++---\r
+ 4 files changed, 25 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index e791bb0..ea836f7 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -148,6 +148,8 @@ typedef enum _notmuch_private_status {\r
+ \r
+ typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;\r
+ \r
++typedef struct _notmuch_string_list notmuch_string_list_t;\r
++\r
+ /* database.cc */\r
+ \r
+ /* Lookup a prefix value by name.\r
+@@ -216,6 +218,7 @@ _notmuch_thread_create (void *ctx,\r
+                       notmuch_database_t *notmuch,\r
+                       unsigned int seed_doc_id,\r
+                       notmuch_doc_id_set_t *match_set,\r
++                      notmuch_string_list_t *excluded_terms,\r
+                       notmuch_sort_t sort);\r
+ \r
+ /* message.cc */\r
+@@ -459,11 +462,11 @@ typedef struct _notmuch_string_node {\r
+     struct _notmuch_string_node *next;\r
+ } notmuch_string_node_t;\r
+ \r
+-typedef struct visible _notmuch_string_list {\r
++struct visible _notmuch_string_list {\r
+     int length;\r
+     notmuch_string_node_t *head;\r
+     notmuch_string_node_t **tail;\r
+-} notmuch_string_list_t;\r
++};\r
+ \r
+ notmuch_string_list_t *\r
+ _notmuch_string_list_create (const void *ctx);\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index f75afae..babd208 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -672,8 +672,10 @@ notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);\r
+ /* Get the number of messages in 'thread' that matched the search.\r
+  *\r
+  * This count includes only the messages in this thread that were\r
+- * matched by the search from which the thread was created. Contrast\r
+- * with notmuch_thread_get_total_messages() .\r
++ * matched by the search from which the thread was created and were\r
++ * not excluded by any exclude tags passed in with the query (see\r
++ * notmuch_query_add_tag_exclude). Contrast with\r
++ * notmuch_thread_get_total_messages() .\r
+  */\r
+ int\r
+ notmuch_thread_get_matched_messages (notmuch_thread_t *thread);\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index ef2a11f..ab18fbc 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -475,6 +475,7 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
+                                  threads->query->notmuch,\r
+                                  doc_id,\r
+                                  &threads->match_set,\r
++                                 threads->query->exclude_terms,\r
+                                  threads->query->sort);\r
+ }\r
+ \r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index 0435ee6..e976d64 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -214,7 +214,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,\r
+  */\r
+ static void\r
+ _thread_add_message (notmuch_thread_t *thread,\r
+-                   notmuch_message_t *message)\r
++                   notmuch_message_t *message,\r
++                   notmuch_string_list_t *exclude_terms)\r
+ {\r
+     notmuch_tags_t *tags;\r
+     const char *tag;\r
+@@ -262,6 +263,15 @@ _thread_add_message (notmuch_thread_t *thread,\r
+        notmuch_tags_move_to_next (tags))\r
+     {\r
+       tag = notmuch_tags_get (tags);\r
++      /* Mark excluded messages. */\r
++      for (notmuch_string_node_t *term = exclude_terms->head; term;\r
++           term = term->next) {\r
++          /* We ignore initial 'K'. */\r
++          if (strcmp(tag, (term->string + 1)) == 0) {\r
++              notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
++              break;\r
++          }\r
++      }\r
+       g_hash_table_insert (thread->tags, xstrdup (tag), NULL);\r
+     }\r
+ }\r
+@@ -321,7 +331,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
+           _thread_set_subject_from_message (thread, message);\r
+     }\r
+ \r
+-    thread->matched_messages++;\r
++    if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))\r
++      thread->matched_messages++;\r
+ \r
+     if (g_hash_table_lookup_extended (thread->message_hash,\r
+                           notmuch_message_get_message_id (message), NULL,\r
+@@ -392,6 +403,7 @@ _notmuch_thread_create (void *ctx,\r
+                       notmuch_database_t *notmuch,\r
+                       unsigned int seed_doc_id,\r
+                       notmuch_doc_id_set_t *match_set,\r
++                      notmuch_string_list_t *exclude_terms,\r
+                       notmuch_sort_t sort)\r
+ {\r
+     notmuch_thread_t *thread;\r
+@@ -467,7 +479,7 @@ _notmuch_thread_create (void *ctx,\r
+       if (doc_id == seed_doc_id)\r
+           message = seed_message;\r
+ \r
+-      _thread_add_message (thread, message);\r
++      _thread_add_message (thread, message, exclude_terms);\r
+ \r
+       if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {\r
+           _notmuch_doc_id_set_remove (match_set, doc_id);\r
+-- \r
+1.7.2.3\r
+\r