Re: [PATCH v3] nmbug: Translate to Python
[notmuch-archives.git] / 17 / 77b926b670f0ab0c6dec6409d84406fc1a4409
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 B8C5841ED83\r
6         for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:03:16 -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 r565b7f7E+OI for <notmuch@notmuchmail.org>;\r
18         Wed, 15 Feb 2012 01:03:12 -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 94DE0421192\r
23         for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:03:03 -0800 (PST)\r
24 Received: by wibhi8 with SMTP id hi8so453259wib.26\r
25         for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:03:02 -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=IqeCmc2ELfjZkxjYdYxRGHL3vbcGmotc+462IZgK1tU=;\r
29         b=s5SvO4gALtjXXTMHfdXhVLFfiKqUmc8KU59IGWlZtfqRZIryl1EzHxf8ldEbxzHSrQ\r
30         VJwBXLxg6MjH11k5nz+GQWqFal/+owwwETrN2Zq0FLpPIpXxeQBVsfJ0w7rDMfOMwXB4\r
31         XgS+METwaNFn4C8Rmlp6zbOABlAaCnB8YrFFE=\r
32 Received: by 10.180.96.8 with SMTP id do8mr6983347wib.21.1329296582430;\r
33         Wed, 15 Feb 2012 01:03:02 -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  da8sm32095611wib.6.2012.02.15.01.03.00 (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Wed, 15 Feb 2012 01:03:01 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [RFC PATCH v5 04/11] lib: Rearrange the exclude code in query.cc\r
41 Date: Wed, 15 Feb 2012 09:03:32 +0000\r
42 Message-Id: <1329296619-7463-5-git-send-email-markwalters1009@gmail.com>\r
43 X-Mailer: git-send-email 1.7.2.3\r
44 In-Reply-To: <1329296619-7463-1-git-send-email-markwalters1009@gmail.com>\r
45 References: <1329296619-7463-1-git-send-email-markwalters1009@gmail.com>\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Wed, 15 Feb 2012 09:03:17 -0000\r
59 \r
60 Slightly refactor the exclude code to give the callers access to the\r
61 exclude query itself. There should be no functional change.\r
62 ---\r
63  lib/query.cc |   29 +++++++++++++++++++----------\r
64  1 files changed, 19 insertions(+), 10 deletions(-)\r
65 \r
66 diff --git a/lib/query.cc b/lib/query.cc\r
67 index 0b36602..c25b301 100644\r
68 --- a/lib/query.cc\r
69 +++ b/lib/query.cc\r
70 @@ -122,12 +122,15 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)\r
71      return 0;\r
72  }\r
73  \r
74 -/* Return a query that does not match messages with the excluded tags\r
75 - * registered with the query.  Any tags that explicitly appear in\r
76 - * xquery will not be excluded. */\r
77 +/* Return a query that matches messages with the excluded tags\r
78 + * registered with query.  Any tags that explicitly appear in xquery\r
79 + * will not be excluded. The caller of this function has to combine\r
80 + * the returned query appropriately.*/\r
81  static Xapian::Query\r
82  _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
83  {\r
84 +    Xapian::Query exclude_query = Xapian::Query::MatchNothing;\r
85 +\r
86      for (notmuch_string_node_t *term = query->exclude_terms->head; term;\r
87          term = term->next) {\r
88         Xapian::TermIterator it = xquery.get_terms_begin ();\r
89 @@ -137,10 +140,10 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
90                 break;\r
91         }\r
92         if (it == end)\r
93 -           xquery = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
94 -                                   xquery, Xapian::Query (term->string));\r
95 +           exclude_query = Xapian::Query (Xapian::Query::OP_OR,\r
96 +                                   exclude_query, Xapian::Query (term->string));\r
97      }\r
98 -    return xquery;\r
99 +    return exclude_query;\r
100  }\r
101  \r
102  notmuch_messages_t *\r
103 @@ -168,7 +171,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
104         Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
105                                                    _find_prefix ("type"),\r
106                                                    "mail"));\r
107 -       Xapian::Query string_query, final_query;\r
108 +       Xapian::Query string_query, final_query, exclude_query;\r
109         Xapian::MSet mset;\r
110         unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
111                               Xapian::QueryParser::FLAG_PHRASE |\r
112 @@ -188,7 +191,10 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
113                                          mail_query, string_query);\r
114         }\r
115  \r
116 -       final_query = _notmuch_exclude_tags (query, final_query);\r
117 +       exclude_query = _notmuch_exclude_tags (query, final_query);\r
118 +\r
119 +       final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
120 +                                        final_query, exclude_query);\r
121  \r
122         enquire.set_weighting_scheme (Xapian::BoolWeight());\r
123  \r
124 @@ -449,7 +455,7 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
125         Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
126                                                    _find_prefix ("type"),\r
127                                                    "mail"));\r
128 -       Xapian::Query string_query, final_query;\r
129 +       Xapian::Query string_query, final_query, exclude_query;\r
130         Xapian::MSet mset;\r
131         unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
132                               Xapian::QueryParser::FLAG_PHRASE |\r
133 @@ -469,7 +475,10 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
134                                          mail_query, string_query);\r
135         }\r
136  \r
137 -       final_query = _notmuch_exclude_tags (query, final_query);\r
138 +       exclude_query = _notmuch_exclude_tags (query, final_query);\r
139 +\r
140 +       final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
141 +                                        final_query, exclude_query);\r
142  \r
143         enquire.set_weighting_scheme(Xapian::BoolWeight());\r
144         enquire.set_docid_order(Xapian::Enquire::ASCENDING);\r
145 -- \r
146 1.7.2.3\r
147 \r