~vcs-imports/notmuch/trunk

« back to all changes in this revision

Viewing changes to lib/query.cc

  • Committer: David Bremner
  • Author(s): Austin Clements
  • Date: 2012-03-18 12:14:22 UTC
  • Revision ID: git-v1:75a05526334b721d719d6c8a8098ff64573e6c1e
lib: Expose query debug output via an environment variable

Allow query debugging to be enabled at run-time by setting the
NOTMUCH_DEBUG_QUERY environment variable to a non-empty string.

Previously, enabling query debugging required recompiling, but parsed
queries are often useful for tracking down bugs in situations where
recompiling is inconvenient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
                          notmuch_doc_id_set_t *doc_ids,
65
65
                          GArray *arr);
66
66
 
 
67
static notmuch_bool_t
 
68
_debug_query (void)
 
69
{
 
70
    char *env = getenv ("NOTMUCH_DEBUG_QUERY");
 
71
    return (env && strcmp (env, "") != 0);
 
72
}
 
73
 
67
74
notmuch_query_t *
68
75
notmuch_query_create (notmuch_database_t *notmuch,
69
76
                      const char *query_string)
70
77
{
71
78
    notmuch_query_t *query;
72
79
 
73
 
#ifdef DEBUG_QUERY
74
 
    fprintf (stderr, "Query string is:\n%s\n", query_string);
75
 
#endif
 
80
    if (_debug_query ())
 
81
        fprintf (stderr, "Query string is:\n%s\n", query_string);
76
82
 
77
83
    query = talloc (NULL, notmuch_query_t);
78
84
    if (unlikely (query == NULL))
255
261
            break;
256
262
        }
257
263
 
258
 
#if DEBUG_QUERY
259
 
        fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str());
260
 
#endif
 
264
        if (_debug_query ())
 
265
            fprintf (stderr, "Final query is:\n%s\n",
 
266
                     final_query.get_description ().c_str ());
261
267
 
262
268
        enquire.set_query (final_query);
263
269
 
531
537
        enquire.set_weighting_scheme(Xapian::BoolWeight());
532
538
        enquire.set_docid_order(Xapian::Enquire::ASCENDING);
533
539
 
534
 
#if DEBUG_QUERY
535
 
        fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str());
536
 
#endif
 
540
        if (_debug_query ())
 
541
            fprintf (stderr, "Final query is:\n%s\n",
 
542
                     final_query.get_description ().c_str ());
537
543
 
538
544
        enquire.set_query (final_query);
539
545