1 Return-Path: <markwalters1009@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 2FCD4429E49
\r
6 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 10:39:11 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,
\r
14 RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id Xw+wIC6qYBhc for <notmuch@notmuchmail.org>;
\r
18 Sun, 29 Jan 2012 10:39:10 -0800 (PST)
\r
19 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com
\r
20 [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id 4BD01429E43
\r
23 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 10:39:10 -0800 (PST)
\r
24 Received: by mail-wi0-f181.google.com with SMTP id hi8so2994807wib.26
\r
25 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 10:39:10 -0800 (PST)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
28 bh=P+f8xzUbfqdG58l/BpPjc+oiqK9CMwdpnipExgONsms=;
\r
29 b=sX4oY2ie3y5KlDWqZQnpY0Zk4l9XSolGYFRqgyp/zwfm2lG+YWtB1j2hAzWV/js3HE
\r
30 DGyhLB/F7ssoORdk2kN8Np36qmNEBEKxJYV7XtACMDyZK2SggUNltdX31jeZ+L4mC6rA
\r
31 nI/XgjASiasQR1A2MxcW1DAOwNFHBDcyr/zkU=
\r
32 Received: by 10.180.87.8 with SMTP id t8mr23643961wiz.15.1327862350047;
\r
33 Sun, 29 Jan 2012 10:39:10 -0800 (PST)
\r
34 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.
\r
35 [94.192.233.223]) by mx.google.com with ESMTPS id
\r
36 t6sm25224025wid.1.2012.01.29.10.39.08 (version=TLSv1/SSLv3 cipher=OTHER);
\r
37 Sun, 29 Jan 2012 10:39:09 -0800 (PST)
\r
38 From: Mark Walters <markwalters1009@gmail.com>
\r
39 To: notmuch@notmuchmail.org,
\r
41 Subject: [PATCH 3/7] lib: Make notmuch_query_search_messages set the exclude
\r
43 Date: Sun, 29 Jan 2012 18:39:50 +0000
\r
44 Message-Id: <1327862394-14334-3-git-send-email-markwalters1009@gmail.com>
\r
45 X-Mailer: git-send-email 1.7.2.3
\r
46 In-Reply-To: <8762fu4aqt.fsf@qmul.ac.uk>
\r
47 References: <8762fu4aqt.fsf@qmul.ac.uk>
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.13
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Sun, 29 Jan 2012 18:39:11 -0000
\r
62 Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by
\r
63 notmuch_query_search_messages for excluded messages. Also add an
\r
64 option omit_excluded_messages to the search that we do not want the
\r
67 This exclude flag will be added to notmuch_query_search threads in the
\r
70 lib/notmuch-private.h | 1 +
\r
71 lib/notmuch.h | 8 ++++++-
\r
72 lib/query.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++---
\r
73 3 files changed, 56 insertions(+), 5 deletions(-)
\r
75 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
76 index 7bf153e..e791bb0 100644
\r
77 --- a/lib/notmuch-private.h
\r
78 +++ b/lib/notmuch-private.h
\r
79 @@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {
\r
81 struct visible _notmuch_messages {
\r
82 notmuch_bool_t is_of_list_type;
\r
83 + notmuch_doc_id_set_t *excluded_doc_ids;
\r
84 notmuch_message_node_t *iterator;
\r
87 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
88 index 7929fe7..740d005 100644
\r
91 @@ -449,6 +449,11 @@ typedef enum {
\r
93 notmuch_query_get_query_string (notmuch_query_t *query);
\r
95 +/* specify whether to results should omit the excluded results rather
\r
96 + * than just marking them excluded */
\r
98 +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);
\r
100 /* Specify the sorting desired for this query. */
\r
102 notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
\r
103 @@ -895,7 +900,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);
\r
105 /* Message flags */
\r
106 typedef enum _notmuch_message_flag {
\r
107 - NOTMUCH_MESSAGE_FLAG_MATCH
\r
108 + NOTMUCH_MESSAGE_FLAG_MATCH,
\r
109 + NOTMUCH_MESSAGE_FLAG_EXCLUDED
\r
110 } notmuch_message_flag_t;
\r
112 /* Get a value of a flag for the email corresponding to 'message'. */
\r
113 diff --git a/lib/query.cc b/lib/query.cc
\r
114 index c25b301..7d165d2 100644
\r
117 @@ -28,6 +28,7 @@ struct _notmuch_query {
\r
118 const char *query_string;
\r
119 notmuch_sort_t sort;
\r
120 notmuch_string_list_t *exclude_terms;
\r
121 + notmuch_bool_t omit_excluded_messages;
\r
124 typedef struct _notmuch_mset_messages {
\r
125 @@ -57,6 +58,12 @@ struct visible _notmuch_threads {
\r
126 notmuch_doc_id_set_t match_set;
\r
129 +/* we need this in the message functions so forward declare */
\r
130 +static notmuch_bool_t
\r
131 +_notmuch_doc_id_set_init (void *ctx,
\r
132 + notmuch_doc_id_set_t *doc_ids,
\r
136 notmuch_query_create (notmuch_database_t *notmuch,
\r
137 const char *query_string)
\r
138 @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,
\r
140 query->exclude_terms = _notmuch_string_list_create (query);
\r
142 + query->omit_excluded_messages = FALSE;
\r
147 @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)
\r
151 +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)
\r
153 + query->omit_excluded_messages = omit;
\r
157 notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)
\r
159 query->sort = sort;
\r
160 @@ -173,6 +188,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
162 Xapian::Query string_query, final_query, exclude_query;
\r
164 + Xapian::MSetIterator iterator;
\r
165 unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
\r
166 Xapian::QueryParser::FLAG_PHRASE |
\r
167 Xapian::QueryParser::FLAG_LOVEHATE |
\r
168 @@ -190,11 +206,35 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
169 final_query = Xapian::Query (Xapian::Query::OP_AND,
\r
170 mail_query, string_query);
\r
172 + messages->base.excluded_doc_ids = NULL;
\r
174 + if (query->exclude_terms) {
\r
175 + exclude_query = _notmuch_exclude_tags (query, final_query);
\r
176 + exclude_query = Xapian::Query (Xapian::Query::OP_AND,
\r
177 + exclude_query, final_query);
\r
179 + if (query->omit_excluded_messages)
\r
180 + final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
\r
181 + final_query, exclude_query);
\r
183 + enquire.set_weighting_scheme (Xapian::BoolWeight());
\r
184 + enquire.set_query (exclude_query);
\r
186 + mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());
\r
188 + GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));
\r
190 + for (iterator = mset.begin (); iterator != mset.end (); iterator++)
\r
192 + unsigned int doc_id = *iterator;
\r
193 + g_array_append_val (excluded_doc_ids, doc_id);
\r
195 + messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);
\r
196 + _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,
\r
197 + excluded_doc_ids);
\r
201 - exclude_query = _notmuch_exclude_tags (query, final_query);
\r
203 - final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
\r
204 - final_query, exclude_query);
\r
206 enquire.set_weighting_scheme (Xapian::BoolWeight());
\r
208 @@ -283,6 +323,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)
\r
209 INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");
\r
212 + if ((messages->excluded_doc_ids) &&
\r
213 + (_notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id)))
\r
214 + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);
\r