From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org, Austin Clements <amdragon@MIT.EDU>
Subject: [Patch v6 04/13] lib: Rearrange the exclude code in query.cc
Date: Sat, 25 Feb 2012 08:06:35 +0000 [thread overview]
Message-ID: <1330157204-26094-5-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1330157204-26094-1-git-send-email-markwalters1009@gmail.com>
Slightly refactor the exclude code to give the callers access to the
exclude query itself. There should be no functional change.
---
lib/query.cc | 29 +++++++++++++++++++----------
1 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/lib/query.cc b/lib/query.cc
index 0b36602..c25b301 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -122,12 +122,15 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)
return 0;
}
-/* Return a query that does not match messages with the excluded tags
- * registered with the query. Any tags that explicitly appear in
- * xquery will not be excluded. */
+/* Return a query that matches messages with the excluded tags
+ * registered with query. Any tags that explicitly appear in xquery
+ * will not be excluded. The caller of this function has to combine
+ * the returned query appropriately.*/
static Xapian::Query
_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
{
+ Xapian::Query exclude_query = Xapian::Query::MatchNothing;
+
for (notmuch_string_node_t *term = query->exclude_terms->head; term;
term = term->next) {
Xapian::TermIterator it = xquery.get_terms_begin ();
@@ -137,10 +140,10 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
break;
}
if (it == end)
- xquery = Xapian::Query (Xapian::Query::OP_AND_NOT,
- xquery, Xapian::Query (term->string));
+ exclude_query = Xapian::Query (Xapian::Query::OP_OR,
+ exclude_query, Xapian::Query (term->string));
}
- return xquery;
+ return exclude_query;
}
notmuch_messages_t *
@@ -168,7 +171,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
_find_prefix ("type"),
"mail"));
- Xapian::Query string_query, final_query;
+ Xapian::Query string_query, final_query, exclude_query;
Xapian::MSet mset;
unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
Xapian::QueryParser::FLAG_PHRASE |
@@ -188,7 +191,10 @@ notmuch_query_search_messages (notmuch_query_t *query)
mail_query, string_query);
}
- final_query = _notmuch_exclude_tags (query, final_query);
+ exclude_query = _notmuch_exclude_tags (query, final_query);
+
+ final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
+ final_query, exclude_query);
enquire.set_weighting_scheme (Xapian::BoolWeight());
@@ -449,7 +455,7 @@ notmuch_query_count_messages (notmuch_query_t *query)
Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
_find_prefix ("type"),
"mail"));
- Xapian::Query string_query, final_query;
+ Xapian::Query string_query, final_query, exclude_query;
Xapian::MSet mset;
unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
Xapian::QueryParser::FLAG_PHRASE |
@@ -469,7 +475,10 @@ notmuch_query_count_messages (notmuch_query_t *query)
mail_query, string_query);
}
- final_query = _notmuch_exclude_tags (query, final_query);
+ exclude_query = _notmuch_exclude_tags (query, final_query);
+
+ final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
+ final_query, exclude_query);
enquire.set_weighting_scheme(Xapian::BoolWeight());
enquire.set_docid_order(Xapian::Enquire::ASCENDING);
--
1.7.2.3
next prev parent reply other threads:[~2012-02-26 3:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-25 8:06 [Patch v6 00/13] Add NOTMUCH_MESSAGE_FLAG_EXCLUDED flag Mark Walters
2012-02-25 8:06 ` [Patch v6 01/13] cli: add --no-exclude option to count and search Mark Walters
2012-02-25 8:06 ` [Patch v6 02/13] cli: Add --no-exclude to the man pages for search and count Mark Walters
2012-02-25 8:06 ` [Patch v6 03/13] test: add tests for new cli --no-exclude option Mark Walters
2012-02-25 8:06 ` Mark Walters [this message]
2012-02-25 8:06 ` [Patch v6 05/13] lib: Make notmuch_query_search_messages set the exclude flag Mark Walters
2012-02-25 8:06 ` [Patch v6 06/13] lib: Add the exclude flag to notmuch_query_search_threads Mark Walters
2012-02-25 8:06 ` [Patch v6 07/13] test: update search test to reflect exclude flag Mark Walters
2012-02-25 8:06 ` [Patch v6 08/13] cli: Make notmuch-show respect excludes Mark Walters
2012-02-25 8:06 ` [Patch v6 09/13] test: update tests to reflect the exclude flag Mark Walters
2012-02-25 8:06 ` [Patch v6 10/13] man: update manpage for notmuch-show --no-exclude option Mark Walters
2012-02-25 8:06 ` [Patch v6 11/13] cli: omit excluded messages in results where appropriate Mark Walters
2012-02-25 8:06 ` [Patch v6 12/13] emacs: show: recognize the exclude flag Mark Walters
2012-02-29 9:17 ` Mark Walters
2012-02-25 8:06 ` [Patch v6 13/13] emacs: notmuch.el ignore excluded matches Mark Walters
2012-02-27 22:39 ` [Patch v6 00/13] Add NOTMUCH_MESSAGE_FLAG_EXCLUDED flag Austin Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1330157204-26094-5-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=amdragon@MIT.EDU \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).