X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fquery.cc;h=e9c1a2d158e5d613ab129026ecf98976d1077265;hp=ab18fbc6124d1c573741a9ebc7ac2dbb77b65086;hb=af6b4b29f97b1f457bb7220491bf37536e1b9d7a;hpb=1a53f9f116fa7c460cda3df532be921baaafb082 diff --git a/lib/query.cc b/lib/query.cc index ab18fbc6..e9c1a2d1 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -28,7 +28,7 @@ struct _notmuch_query { const char *query_string; notmuch_sort_t sort; notmuch_string_list_t *exclude_terms; - notmuch_bool_t omit_excluded_messages; + notmuch_bool_t omit_excluded; }; typedef struct _notmuch_mset_messages { @@ -64,15 +64,21 @@ _notmuch_doc_id_set_init (void *ctx, notmuch_doc_id_set_t *doc_ids, GArray *arr); +static notmuch_bool_t +_debug_query (void) +{ + char *env = getenv ("NOTMUCH_DEBUG_QUERY"); + return (env && strcmp (env, "") != 0); +} + notmuch_query_t * notmuch_query_create (notmuch_database_t *notmuch, const char *query_string) { notmuch_query_t *query; -#ifdef DEBUG_QUERY - fprintf (stderr, "Query string is:\n%s\n", query_string); -#endif + if (_debug_query ()) + fprintf (stderr, "Query string is:\n%s\n", query_string); query = talloc (NULL, notmuch_query_t); if (unlikely (query == NULL)) @@ -86,7 +92,7 @@ notmuch_query_create (notmuch_database_t *notmuch, query->exclude_terms = _notmuch_string_list_create (query); - query->omit_excluded_messages = FALSE; + query->omit_excluded = TRUE; return query; } @@ -98,9 +104,9 @@ notmuch_query_get_query_string (notmuch_query_t *query) } void -notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit) +notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded) { - query->omit_excluded_messages = omit; + query->omit_excluded = omit_excluded; } void @@ -213,13 +219,14 @@ notmuch_query_search_messages (notmuch_query_t *query) if (query->exclude_terms) { exclude_query = _notmuch_exclude_tags (query, final_query); - exclude_query = Xapian::Query (Xapian::Query::OP_AND, - exclude_query, final_query); - if (query->omit_excluded_messages) + if (query->omit_excluded) final_query = Xapian::Query (Xapian::Query::OP_AND_NOT, final_query, exclude_query); else { + exclude_query = Xapian::Query (Xapian::Query::OP_AND, + exclude_query, final_query); + enquire.set_weighting_scheme (Xapian::BoolWeight()); enquire.set_query (exclude_query); @@ -255,9 +262,12 @@ notmuch_query_search_messages (notmuch_query_t *query) break; } -#if DEBUG_QUERY - fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str()); -#endif + if (_debug_query ()) { + fprintf (stderr, "Exclude query is:\n%s\n", + exclude_query.get_description ().c_str ()); + fprintf (stderr, "Final query is:\n%s\n", + final_query.get_description ().c_str ()); + } enquire.set_query (final_query); @@ -531,9 +541,12 @@ notmuch_query_count_messages (notmuch_query_t *query) enquire.set_weighting_scheme(Xapian::BoolWeight()); enquire.set_docid_order(Xapian::Enquire::ASCENDING); -#if DEBUG_QUERY - fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str()); -#endif + if (_debug_query ()) { + fprintf (stderr, "Exclude query is:\n%s\n", + exclude_query.get_description ().c_str ()); + fprintf (stderr, "Final query is:\n%s\n", + final_query.get_description ().c_str ()); + } enquire.set_query (final_query);