X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fquery.cc;h=8cf0a077e5e74e54267d0470a25b51fa9e84475d;hb=b8f4e7da3d61733fb47111b162ccabb967a3661e;hp=9279915d21ccfbccb9ad9929a4089695a9f55928;hpb=7a0fc103678ea1b1da2df561d222c08db04c5af2;p=notmuch diff --git a/lib/query.cc b/lib/query.cc index 9279915d..8cf0a077 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -98,7 +98,7 @@ notmuch_query_create (notmuch_database_t *notmuch, } const char * -notmuch_query_get_query_string (notmuch_query_t *query) +notmuch_query_get_query_string (const notmuch_query_t *query) { return query->query_string; } @@ -117,7 +117,7 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort) } notmuch_sort_t -notmuch_query_get_sort (notmuch_query_t *query) +notmuch_query_get_sort (const notmuch_query_t *query) { return query->sort; } @@ -296,9 +296,12 @@ notmuch_query_search_messages_st (notmuch_query_t *query, return NOTMUCH_STATUS_SUCCESS; } catch (const Xapian::Error &error) { - fprintf (stderr, "A Xapian exception occurred performing query: %s\n", - error.get_msg().c_str()); - fprintf (stderr, "Query string was: %s\n", query->query_string); + _notmuch_database_log (notmuch, + "A Xapian exception occurred performing query: %s\n" + "Query string was: %s\n", + error.get_msg().c_str(), + query->query_string); + notmuch->exception_reported = TRUE; talloc_free (messages); return NOTMUCH_STATUS_XAPIAN_EXCEPTION; @@ -587,14 +590,22 @@ notmuch_query_count_messages (notmuch_query_t *query) enquire.set_query (final_query); - mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ()); + /* + * Set the checkatleast parameter to the number of documents + * in the database to make get_matches_estimated() exact. + */ + mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount (), + notmuch->xapian_db->get_doccount ()); count = mset.get_matches_estimated(); } catch (const Xapian::Error &error) { - fprintf (stderr, "A Xapian exception occurred: %s\n", - error.get_msg().c_str()); - fprintf (stderr, "Query string was: %s\n", query->query_string); + _notmuch_database_log (notmuch, + "A Xapian exception occurred performing query: %s\n" + "Query string was: %s\n", + error.get_msg().c_str(), + query->query_string); + } return count; @@ -607,10 +618,14 @@ notmuch_query_count_threads (notmuch_query_t *query) GHashTable *hash; unsigned int count; notmuch_sort_t sort; + notmuch_status_t status; sort = query->sort; query->sort = NOTMUCH_SORT_UNSORTED; - messages = notmuch_query_search_messages (query); + status = notmuch_query_search_messages_st (query, &messages); + if (status) + return 0; + query->sort = sort; if (messages == NULL) return 0; @@ -643,3 +658,9 @@ notmuch_query_count_threads (notmuch_query_t *query) return count; } + +notmuch_database_t * +notmuch_query_get_database (const notmuch_query_t *query) +{ + return query->notmuch; +}