[PATCH v4 05/11] lib: Make notmuch_query_search_messages set the exclude flag
authorMark Walters <markwalters1009@gmail.com>
Thu, 2 Feb 2012 17:43:33 +0000 (17:43 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:57 +0000 (09:43 -0800)
3b/b6a281b00da7aba08bb686ec8c2f1038e3c620 [new file with mode: 0644]

diff --git a/3b/b6a281b00da7aba08bb686ec8c2f1038e3c620 b/3b/b6a281b00da7aba08bb686ec8c2f1038e3c620
new file mode 100644 (file)
index 0000000..a6b820c
--- /dev/null
@@ -0,0 +1,223 @@
+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 3400C431FD4\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 09:43:07 -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 qySTS829QVKn for <notmuch@notmuchmail.org>;\r
+       Thu,  2 Feb 2012 09:43:04 -0800 (PST)\r
+Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
+ [74.125.82.45])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ AAE2F431FBD   for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 09:43:04 -0800\r
+ (PST)\r
+Received: by mail-ww0-f45.google.com with SMTP id dt12so2522817wgb.2\r
+       for <notmuch@notmuchmail.org>; Thu, 02 Feb 2012 09:43:04 -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=knt5sXht2CAdKNYRxCMo1wlZF5hCNBmCpK6XfOE0xLg=;\r
+       b=SL3GfB21XFzC6DnwFKVs2TsjM7cMmRbxQCobXKcKLomKyVq5wHa0qSF7iiubCFRAqK\r
+       DvNClHCz35sLD5NC/TzMoPYutc7X/Kce6VWqjuOU7fy10EEOJOHG4BlKGSmWOjDS32XC\r
+       rY+KrmVbh8bZHUCUs7ghLrDbtbVK2G0yYR0QE=\r
+Received: by 10.180.107.34 with SMTP id gz2mr6082206wib.21.1328204584353;\r
+       Thu, 02 Feb 2012 09:43:04 -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
+ bj10sm1113555wib.9.2012.02.02.09.43.02        (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 02 Feb 2012 09:43:03 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org,\r
+       amdragon@MIT.EDU\r
+Subject: [PATCH v4 05/11] lib: Make notmuch_query_search_messages set the\r
+       exclude flag\r
+Date: Thu,  2 Feb 2012 17:43:33 +0000\r
+Message-Id: <1328204619-25046-5-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:07 -0000\r
+\r
+Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by\r
+notmuch_query_search_messages for excluded messages. Also add an\r
+option omit_excluded_messages to the search that we do not want the\r
+excludes at all.\r
+\r
+This exclude flag will be added to notmuch_query_search threads in the\r
+next patch.\r
+---\r
+ lib/notmuch-private.h |    1 +\r
+ lib/notmuch.h         |   10 ++++++++-\r
+ lib/query.cc          |   52 +++++++++++++++++++++++++++++++++++++++++++++---\r
+ 3 files changed, 58 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 7bf153e..e791bb0 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {\r
+  */\r
+ struct visible _notmuch_messages {\r
+     notmuch_bool_t is_of_list_type;\r
++    notmuch_doc_id_set_t *excluded_doc_ids;\r
+     notmuch_message_node_t *iterator;\r
+ };\r
\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 7929fe7..f75afae 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -449,6 +449,13 @@ typedef enum {\r
+ const char *\r
+ notmuch_query_get_query_string (notmuch_query_t *query);\r
\r
++/* Specify whether to results should omit the excluded results rather\r
++ * than just marking them excluded. This is useful for passing a\r
++ * notmuch_messages_t not containing the excluded messages to other\r
++ * functions. */\r
++void\r
++notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);\r
++\r
+ /* Specify the sorting desired for this query. */\r
+ void\r
+ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
+@@ -895,7 +902,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
\r
+ /* Message flags */\r
+ typedef enum _notmuch_message_flag {\r
+-    NOTMUCH_MESSAGE_FLAG_MATCH\r
++    NOTMUCH_MESSAGE_FLAG_MATCH,\r
++    NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
+ } notmuch_message_flag_t;\r
\r
+ /* Get a value of a flag for the email corresponding to 'message'. */\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index c25b301..90a71a1 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -28,6 +28,7 @@ struct _notmuch_query {\r
+     const char *query_string;\r
+     notmuch_sort_t sort;\r
+     notmuch_string_list_t *exclude_terms;\r
++    notmuch_bool_t omit_excluded_messages;\r
+ };\r
\r
+ typedef struct _notmuch_mset_messages {\r
+@@ -57,6 +58,12 @@ struct visible _notmuch_threads {\r
+     notmuch_doc_id_set_t match_set;\r
+ };\r
\r
++/* We need this in the message functions so forward declare. */\r
++static notmuch_bool_t\r
++_notmuch_doc_id_set_init (void *ctx,\r
++                        notmuch_doc_id_set_t *doc_ids,\r
++                        GArray *arr);\r
++\r
+ notmuch_query_t *\r
+ notmuch_query_create (notmuch_database_t *notmuch,\r
+                     const char *query_string)\r
+@@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
\r
+     query->exclude_terms = _notmuch_string_list_create (query);\r
\r
++    query->omit_excluded_messages = FALSE;\r
++\r
+     return query;\r
+ }\r
\r
+@@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
+ }\r
\r
+ void\r
++notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)\r
++{\r
++    query->omit_excluded_messages = omit;\r
++}\r
++\r
++void\r
+ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)\r
+ {\r
+     query->sort = sort;\r
+@@ -173,6 +188,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+                                                  "mail"));\r
+       Xapian::Query string_query, final_query, exclude_query;\r
+       Xapian::MSet mset;\r
++      Xapian::MSetIterator iterator;\r
+       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+                             Xapian::QueryParser::FLAG_PHRASE |\r
+                             Xapian::QueryParser::FLAG_LOVEHATE |\r
+@@ -190,11 +206,35 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+           final_query = Xapian::Query (Xapian::Query::OP_AND,\r
+                                        mail_query, string_query);\r
+       }\r
++      messages->base.excluded_doc_ids = NULL;\r
++\r
++      if (query->exclude_terms) {\r
++          exclude_query = _notmuch_exclude_tags (query, final_query);\r
++          exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
++                                         exclude_query, final_query);\r
++\r
++          if (query->omit_excluded_messages)\r
++              final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
++                                           final_query, exclude_query);\r
++          else {\r
++              enquire.set_weighting_scheme (Xapian::BoolWeight());\r
++              enquire.set_query (exclude_query);\r
++\r
++              mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
++\r
++              GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
++\r
++              for (iterator = mset.begin (); iterator != mset.end (); iterator++) {\r
++                  unsigned int doc_id = *iterator;\r
++                  g_array_append_val (excluded_doc_ids, doc_id);\r
++              }\r
++              messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);\r
++              _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
++                                        excluded_doc_ids);\r
++              g_array_unref (excluded_doc_ids);\r
++          }\r
++      }\r
\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
+@@ -283,6 +323,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
+       INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
+     }\r
\r
++    if (messages->excluded_doc_ids &&\r
++      _notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id))\r
++      notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
++\r
+     return message;\r
+ }\r
\r
+-- \r
+1.7.2.3\r
+\r