notmuch search and tags
[notmuch-archives.git] / 29 / aa4e16aad6f81ac87c8e35455d567b30735caf
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 4C81A429E26\r
6         for <notmuch@notmuchmail.org>; Sat, 28 Jan 2012 16:03:27 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \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 PZLhvXNqWBiM for <notmuch@notmuchmail.org>;\r
18         Sat, 28 Jan 2012 16:03:26 -0800 (PST)\r
19 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
20  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  7F30A431FCF    for <notmuch@notmuchmail.org>; Sat, 28 Jan 2012 16:03:25 -0800\r
23  (PST)\r
24 Received: by wgbdt12 with SMTP id dt12so2911093wgb.2\r
25         for <notmuch@notmuchmail.org>; Sat, 28 Jan 2012 16:03:24 -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=cWWD+ryMZ5cjav9/3mhertRFmtT9v2Wc8F6x1pFn/4M=;\r
29         b=nW4T4scvQ6jmWSuMJFXylNWMTCvKkDGRbeq71/bxbEIpHVqCvs2DM6aoyHKrgCjNEy\r
30         O5daTBLzlsuSrGRR9zERML9JeVcgQVFnohUkF4IQ5L5DOLNI+/yXzceQ1EImwM5ZAqsM\r
31         CmVzvi8VOny/4cUueXe4G0T9j2hntQdBFVacU=\r
32 Received: by 10.180.89.67 with SMTP id bm3mr19408605wib.13.1327795404210;\r
33         Sat, 28 Jan 2012 16:03:24 -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  n5sm37316151wiw.7.2012.01.28.16.03.22  (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Sat, 28 Jan 2012 16:03:23 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: notmuch@notmuchmail.org,\r
40         amdragon@MIT.EDU\r
41 Subject: [PATCH 2/4] Add exclude flag\r
42 Date: Sun, 29 Jan 2012 00:04:02 +0000\r
43 Message-Id: <1327795444-18745-2-git-send-email-markwalters1009@gmail.com>\r
44 X-Mailer: git-send-email 1.7.2.3\r
45 In-Reply-To: <8739azqt2j.fsf@qmul.ac.uk>\r
46 References: <8739azqt2j.fsf@qmul.ac.uk>\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Sun, 29 Jan 2012 00:03:27 -0000\r
60 \r
61 Make notmuch_query_search_messages set the exclude flag\r
62 \r
63 Exclude flag will be added to notmuch_query_search threads later.\r
64 ---\r
65  lib/notmuch.h |    3 ++-\r
66  lib/query.cc  |   34 +++++++++++++++++++++++++++++++---\r
67  2 files changed, 33 insertions(+), 4 deletions(-)\r
68 \r
69 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
70 index 7929fe7..cf0d45d 100644\r
71 --- a/lib/notmuch.h\r
72 +++ b/lib/notmuch.h\r
73 @@ -895,7 +895,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
74  \r
75  /* Message flags */\r
76  typedef enum _notmuch_message_flag {\r
77 -    NOTMUCH_MESSAGE_FLAG_MATCH\r
78 +    NOTMUCH_MESSAGE_FLAG_MATCH,\r
79 +    NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
80  } notmuch_message_flag_t;\r
81  \r
82  /* Get a value of a flag for the email corresponding to 'message'. */\r
83 diff --git a/lib/query.cc b/lib/query.cc\r
84 index c25b301..8ffafe5 100644\r
85 --- a/lib/query.cc\r
86 +++ b/lib/query.cc\r
87 @@ -57,6 +57,12 @@ struct visible _notmuch_threads {\r
88      notmuch_doc_id_set_t match_set;\r
89  };\r
90  \r
91 +/* we need this in the message functions so forward declare */\r
92 +static notmuch_bool_t\r
93 +_notmuch_doc_id_set_init (void *ctx,\r
94 +                         notmuch_doc_id_set_t *doc_ids,\r
95 +                         GArray *arr);\r
96 +\r
97  notmuch_query_t *\r
98  notmuch_query_create (notmuch_database_t *notmuch,\r
99                       const char *query_string)\r
100 @@ -173,6 +179,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
101                                                    "mail"));\r
102         Xapian::Query string_query, final_query, exclude_query;\r
103         Xapian::MSet mset;\r
104 +       Xapian::MSetIterator iterator;\r
105         unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
106                               Xapian::QueryParser::FLAG_PHRASE |\r
107                               Xapian::QueryParser::FLAG_LOVEHATE |\r
108 @@ -190,11 +197,28 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
109             final_query = Xapian::Query (Xapian::Query::OP_AND,\r
110                                          mail_query, string_query);\r
111         }\r
112 +       if (query->exclude_terms) {\r
113 +           exclude_query = _notmuch_exclude_tags (query, final_query);\r
114 +           exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
115 +                                          exclude_query, final_query);\r
116  \r
117 -       exclude_query = _notmuch_exclude_tags (query, final_query);\r
118 +           enquire.set_weighting_scheme (Xapian::BoolWeight());\r
119 +           enquire.set_query (exclude_query);\r
120  \r
121 -       final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
122 -                                        final_query, exclude_query);\r
123 +           mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
124 +\r
125 +           GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
126 +\r
127 +           for (iterator = mset.begin (); iterator != mset.end (); iterator++)\r
128 +           {\r
129 +               unsigned int doc_id = *iterator;\r
130 +               g_array_append_val (excluded_doc_ids, doc_id);\r
131 +           }\r
132 +           messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);\r
133 +           _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
134 +                                 excluded_doc_ids);\r
135 +       } else\r
136 +           messages->base.excluded_doc_ids = NULL;\r
137  \r
138         enquire.set_weighting_scheme (Xapian::BoolWeight());\r
139  \r
140 @@ -283,6 +307,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
141         INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
142      }\r
143  \r
144 +    if ((messages->excluded_doc_ids) &&\r
145 +       (_notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id)))\r
146 +       notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
147 +\r
148      return message;\r
149  }\r
150  \r
151 -- \r
152 1.7.2.3\r
153 \r