lib: Rearrange the exclude code in query.cc

Slightly refactor the exclude code to give the callers access to the
exclude query itself. There should be no functional change.
This commit is contained in:
Mark Walters 2012-03-01 22:30:36 +00:00 committed by David Bremner
parent 98f5b0f09a
commit 08f7b026a9

View file

@ -122,12 +122,15 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)
return 0; return 0;
} }
/* Return a query that does not match messages with the excluded tags /* Return a query that matches messages with the excluded tags
* registered with the query. Any tags that explicitly appear in * registered with query. Any tags that explicitly appear in xquery
* xquery will not be excluded. */ * will not be excluded. The caller of this function has to combine
* the returned query appropriately.*/
static Xapian::Query static Xapian::Query
_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery) _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; for (notmuch_string_node_t *term = query->exclude_terms->head; term;
term = term->next) { term = term->next) {
Xapian::TermIterator it = xquery.get_terms_begin (); Xapian::TermIterator it = xquery.get_terms_begin ();
@ -137,10 +140,10 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
break; break;
} }
if (it == end) if (it == end)
xquery = Xapian::Query (Xapian::Query::OP_AND_NOT, exclude_query = Xapian::Query (Xapian::Query::OP_OR,
xquery, Xapian::Query (term->string)); exclude_query, Xapian::Query (term->string));
} }
return xquery; return exclude_query;
} }
notmuch_messages_t * notmuch_messages_t *
@ -168,7 +171,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
Xapian::Query mail_query (talloc_asprintf (query, "%s%s", Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
_find_prefix ("type"), _find_prefix ("type"),
"mail")); "mail"));
Xapian::Query string_query, final_query; Xapian::Query string_query, final_query, exclude_query;
Xapian::MSet mset; Xapian::MSet mset;
unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN | unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
Xapian::QueryParser::FLAG_PHRASE | Xapian::QueryParser::FLAG_PHRASE |
@ -188,7 +191,10 @@ notmuch_query_search_messages (notmuch_query_t *query)
mail_query, string_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_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", Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
_find_prefix ("type"), _find_prefix ("type"),
"mail")); "mail"));
Xapian::Query string_query, final_query; Xapian::Query string_query, final_query, exclude_query;
Xapian::MSet mset; Xapian::MSet mset;
unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN | unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
Xapian::QueryParser::FLAG_PHRASE | Xapian::QueryParser::FLAG_PHRASE |
@ -469,7 +475,10 @@ notmuch_query_count_messages (notmuch_query_t *query)
mail_query, string_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_weighting_scheme(Xapian::BoolWeight());
enquire.set_docid_order(Xapian::Enquire::ASCENDING); enquire.set_docid_order(Xapian::Enquire::ASCENDING);