X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fquery.cc;h=7916421e4a0068847a0fc13b71514c1258893a42;hp=2c8d167255bb903a5224d6d5b7ba0408e108bd00;hb=d064bd696ccc443a7ece9cfc8816999c69943223;hpb=0ea5f3fc0e0336921ba670a28201b59d2c977cfb diff --git a/lib/query.cc b/lib/query.cc index 2c8d1672..7916421e 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -23,8 +23,6 @@ #include /* GHashTable, GPtrArray */ -#include - struct _notmuch_query { notmuch_database_t *notmuch; const char *query_string; @@ -70,12 +68,24 @@ notmuch_query_create (notmuch_database_t *notmuch, return query; } +const char * +notmuch_query_get_query_string (notmuch_query_t *query) +{ + return query->query_string; +} + void notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort) { query->sort = sort; } +notmuch_sort_t +notmuch_query_get_sort (notmuch_query_t *query) +{ + return query->sort; +} + /* We end up having to call the destructors explicitly because we had * to use "placement new" in order to initialize C++ objects within a * block that we allocated with talloc. So C++ is making talloc @@ -125,7 +135,9 @@ notmuch_query_search_messages (notmuch_query_t *query) Xapian::QueryParser::FLAG_WILDCARD | Xapian::QueryParser::FLAG_PURE_NOT); - if (strcmp (query_string, "") == 0) { + if (strcmp (query_string, "") == 0 || + strcmp (query_string, "*") == 0) + { final_query = mail_query; } else { string_query = notmuch->query_parser-> @@ -146,6 +158,8 @@ notmuch_query_search_messages (notmuch_query_t *query) case NOTMUCH_SORT_MESSAGE_ID: enquire.set_sort_by_value (NOTMUCH_VALUE_MESSAGE_ID, FALSE); break; + case NOTMUCH_SORT_UNSORTED: + break; } #if DEBUG_QUERY @@ -159,18 +173,20 @@ notmuch_query_search_messages (notmuch_query_t *query) messages->iterator = mset.begin (); messages->iterator_end = mset.end (); + return &messages->base; + } 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->exception_reported = TRUE; + talloc_free (messages); + return NULL; } - - return &messages->base; } notmuch_bool_t -_notmuch_mset_messages_has_more (notmuch_messages_t *messages) +_notmuch_mset_messages_valid (notmuch_messages_t *messages) { notmuch_mset_messages_t *mset_messages; @@ -189,7 +205,7 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages) mset_messages = (notmuch_mset_messages_t *) messages; - if (! _notmuch_mset_messages_has_more (&mset_messages->base)) + if (! _notmuch_mset_messages_valid (&mset_messages->base)) return NULL; doc_id = *mset_messages->iterator; @@ -208,7 +224,7 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages) } void -_notmuch_mset_messages_advance (notmuch_messages_t *messages) +_notmuch_mset_messages_move_to_next (notmuch_messages_t *messages) { notmuch_mset_messages_t *mset_messages; @@ -243,6 +259,10 @@ notmuch_query_search_threads (notmuch_query_t *query) free, NULL); threads->messages = notmuch_query_search_messages (query); + if (threads->messages == NULL) { + talloc_free (threads); + return NULL; + } threads->thread_id = NULL; @@ -258,14 +278,14 @@ notmuch_query_destroy (notmuch_query_t *query) } notmuch_bool_t -notmuch_threads_has_more (notmuch_threads_t *threads) +notmuch_threads_valid (notmuch_threads_t *threads) { notmuch_message_t *message; if (threads->thread_id) return TRUE; - while (notmuch_messages_has_more (threads->messages)) + while (notmuch_messages_valid (threads->messages)) { message = notmuch_messages_get (threads->messages); @@ -277,11 +297,11 @@ notmuch_threads_has_more (notmuch_threads_t *threads) { g_hash_table_insert (threads->threads, xstrdup (threads->thread_id), NULL); - notmuch_messages_advance (threads->messages); + notmuch_messages_move_to_next (threads->messages); return TRUE; } - notmuch_messages_advance (threads->messages); + notmuch_messages_move_to_next (threads->messages); } threads->thread_id = NULL; @@ -291,17 +311,18 @@ notmuch_threads_has_more (notmuch_threads_t *threads) notmuch_thread_t * notmuch_threads_get (notmuch_threads_t *threads) { - if (! notmuch_threads_has_more (threads)) + if (! notmuch_threads_valid (threads)) return NULL; return _notmuch_thread_create (threads->query, threads->query->notmuch, threads->thread_id, - threads->query->query_string); + threads->query->query_string, + threads->query->sort); } void -notmuch_threads_advance (notmuch_threads_t *threads) +notmuch_threads_move_to_next (notmuch_threads_t *threads) { threads->thread_id = NULL; } @@ -333,7 +354,9 @@ notmuch_query_count_messages (notmuch_query_t *query) Xapian::QueryParser::FLAG_WILDCARD | Xapian::QueryParser::FLAG_PURE_NOT); - if (strcmp (query_string, "") == 0) { + if (strcmp (query_string, "") == 0 || + strcmp (query_string, "*") == 0) + { final_query = mail_query; } else { string_query = notmuch->query_parser->