[PATCH v4 4/7] Add internal functions to search for alternate doc types
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Sat, 9 Apr 2016 01:54:49 +0000 (22:54 +2100)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:21:32 +0000 (16:21 -0700)
bc/d27ede7a0dad23b814f59ea4f3107825bbde6e [new file with mode: 0644]

diff --git a/bc/d27ede7a0dad23b814f59ea4f3107825bbde6e b/bc/d27ede7a0dad23b814f59ea4f3107825bbde6e
new file mode 100644 (file)
index 0000000..a0f0a02
--- /dev/null
@@ -0,0 +1,134 @@
+Return-Path: <dkg@fifthhorseman.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id B77D56DE02DB\r
+ for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 18:55:31 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[AWL=0.000]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 5x3cfAf7VKwl for <notmuch@notmuchmail.org>;\r
+ Fri,  8 Apr 2016 18:55:23 -0700 (PDT)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 15DCE6DE0317\r
+ for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 18:55:08 -0700 (PDT)\r
+Received: from fifthhorseman.net (unknown [201.140.212.132])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id 2673F1006F\r
+ for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 21:55:06 -0400 (EDT)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id 545CC200E0; Fri,  8 Apr 2016 22:54:52 -0300 (ART)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v4 4/7] Add internal functions to search for alternate doc\r
+ types\r
+Date: Fri,  8 Apr 2016 22:54:49 -0300\r
+Message-Id: <1460166892-29721-4-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.8.0.rc3\r
+In-Reply-To: <1460166892-29721-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1459445693-3900-1-git-send-email-dkg@fifthhorseman.net>\r
+ <1460166892-29721-1-git-send-email-dkg@fifthhorseman.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 09 Apr 2016 01:55:31 -0000\r
+\r
+Publicly we are only exposing the non-ghost documents (of "type"\r
+"mail").  But internally we might want to inspect the ghost messages\r
+as well.\r
+\r
+This changeset adds two new private interfaces to queries to recover\r
+information about alternate document types.\r
+---\r
+ lib/notmuch-private.h | 11 +++++++++++\r
+ lib/query.cc          | 18 ++++++++++++++++--\r
+ 2 files changed, 27 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 5dd4770..d95bf31 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -477,6 +477,17 @@ void\r
+ _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,\r
+                             unsigned int doc_id);\r
\r
++/* querying xapian documents by type (e.g. "mail" or "ghost"): */\r
++notmuch_status_t\r
++_notmuch_query_search_documents (notmuch_query_t *query,\r
++                               const char *type,\r
++                               notmuch_messages_t **out);\r
++\r
++notmuch_status_t\r
++_notmuch_query_count_documents (notmuch_query_t *query,\r
++                              const char *type,\r
++                              unsigned *count_out);\r
++\r
+ /* message.cc */\r
\r
+ void\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index e627bfc..77a7926 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -187,6 +187,14 @@ notmuch_status_t\r
+ notmuch_query_search_messages_st (notmuch_query_t *query,\r
+                                 notmuch_messages_t **out)\r
+ {\r
++    return _notmuch_query_search_documents (query, "mail", out);\r
++}\r
++\r
++notmuch_status_t\r
++_notmuch_query_search_documents (notmuch_query_t *query,\r
++                               const char *type,\r
++                               notmuch_messages_t **out)\r
++{\r
+     notmuch_database_t *notmuch = query->notmuch;\r
+     const char *query_string = query->query_string;\r
+     notmuch_mset_messages_t *messages;\r
+@@ -208,7 +216,7 @@ notmuch_query_search_messages_st (notmuch_query_t *query,\r
+       Xapian::Enquire enquire (*notmuch->xapian_db);\r
+       Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
+                                                  _find_prefix ("type"),\r
+-                                                 "mail"));\r
++                                                 type));\r
+       Xapian::Query string_query, final_query, exclude_query;\r
+       Xapian::MSet mset;\r
+       Xapian::MSetIterator iterator;\r
+@@ -554,6 +562,12 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+ notmuch_status_t\r
+ notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
+ {\r
++    return _notmuch_query_count_documents (query, "mail", count_out);\r
++}\r
++\r
++notmuch_status_t\r
++_notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsigned *count_out)\r
++{\r
+     notmuch_database_t *notmuch = query->notmuch;\r
+     const char *query_string = query->query_string;\r
+     Xapian::doccount count = 0;\r
+@@ -562,7 +576,7 @@ notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
+       Xapian::Enquire enquire (*notmuch->xapian_db);\r
+       Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
+                                                  _find_prefix ("type"),\r
+-                                                 "mail"));\r
++                                                 type));\r
+       Xapian::Query string_query, final_query, exclude_query;\r
+       Xapian::MSet mset;\r
+       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+-- \r
+2.8.0.rc3\r
+\r