From 8ad01e4aa804925165023483b6ff1d20b450dcb8 Mon Sep 17 00:00:00 2001 From: djcb Date: Wed, 17 Oct 2012 17:59:33 +0300 Subject: [PATCH] * lib: threading: pre-sort the threaded results, add some more comments --- lib/mu-container.c | 8 ++++---- lib/mu-msg-iter.cc | 3 +++ lib/mu-query.cc | 24 +++++++++++++++--------- lib/mu-threader.c | 12 +++++------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/mu-container.c b/lib/mu-container.c index ed4ce056..73587c92 100644 --- a/lib/mu-container.c +++ b/lib/mu-container.c @@ -548,10 +548,10 @@ thread_info_destroy (MuMsgIterThreadInfo *ti) struct _ThreadInfo { - GHashTable *hash; - const char* format; + GHashTable *hash; + const char *format; }; -typedef struct _ThreadInfo ThreadInfo; +typedef struct _ThreadInfo ThreadInfo; static void @@ -589,7 +589,7 @@ thread_segment_format_string (size_t matchnum) /* get the number of digits needed in a hex-representation of * matchnum */ digitnum = (unsigned) (ceil (log(matchnum)/log(16))); - snprintf (frmt, sizeof(frmt),"%%0%ux", digitnum); + snprintf (frmt, sizeof(frmt), "%%0%ux", digitnum); return frmt; } diff --git a/lib/mu-msg-iter.cc b/lib/mu-msg-iter.cc index 3f6ecbc7..ee0f9bd7 100644 --- a/lib/mu-msg-iter.cc +++ b/lib/mu-msg-iter.cc @@ -57,6 +57,9 @@ public: _matches = _enq.get_mset (0, maxnum); + /* when threading, we calculate the threads for the + * set of matches, then requery/sort based on the + * threading */ if (threads && !_matches.empty()) { _matches.fetch(); diff --git a/lib/mu-query.cc b/lib/mu-query.cc index 90366ba5..71846da7 100644 --- a/lib/mu-query.cc +++ b/lib/mu-query.cc @@ -335,12 +335,11 @@ get_enquire (MuQuery *self, const char *searchexpr, gboolean threads, { Xapian::Enquire enq (self->db()); - /* note, when our result will be *threaded*, we sort - * in our threading code (mu-threader etc.), and don't - * let Xapian do any sorting */ - if (!threads && sortfieldid != MU_MSG_FIELD_ID_NONE) - enq.set_sort_by_value ((Xapian::valueno)sortfieldid, - revert ? true : false); + if (sortfieldid != MU_MSG_FIELD_ID_NONE) + enq.set_sort_by_value ((Xapian::valueno)sortfieldid, + revert ? true : false); + + /* empty or "" means "matchall" */ if (!mu_str_is_empty(searchexpr) && g_strcmp0 (searchexpr, "\"\"") != 0) /* NULL or "" or """" */ enq.set_query(get_query (self, searchexpr, err)); @@ -367,15 +366,22 @@ mu_query_run (MuQuery *self, const char* searchexpr, gboolean threads, MuMsgIter *iter; Xapian::Enquire enq (get_enquire(self, searchexpr, threads, sortfieldid, revert, err)); + + /* get the 'real' maxnum if it was specified as < 0 */ + maxnum <= 0 ? self->db().get_doccount() : maxnum; + iter = mu_msg_iter_new ( reinterpret_cast(&enq), - maxnum <= 0 ? self->db().get_doccount() : maxnum, - threads, threads ? sortfieldid : MU_MSG_FIELD_ID_NONE, + maxnum, threads, + /* in we were *not* using threads, no further sorting + * is needed since Xapian already sorted */ + threads ? sortfieldid : MU_MSG_FIELD_ID_NONE, revert, err); if (err && *err && (*err)->code == MU_ERROR_XAPIAN_MODIFIED) { g_clear_error (err); - return try_requery (self, searchexpr, threads, sortfieldid, + return try_requery (self, searchexpr, threads, + sortfieldid, revert, maxnum, err); } else return iter; diff --git a/lib/mu-threader.c b/lib/mu-threader.c index 587574a7..326818cf 100644 --- a/lib/mu-threader.c +++ b/lib/mu-threader.c @@ -48,12 +48,12 @@ * */ - /* step 1 */ static GHashTable* create_containers (MuMsgIter *iter); /* step 2 */ static MuContainer *find_root_set (GHashTable *ids); static MuContainer* prune_empty_containers (MuContainer *root); /* static void group_root_set_by_subject (GSList *root_set); */ -GHashTable* create_doc_id_thread_path_hash (MuContainer *root, size_t match_num); +GHashTable* create_doc_id_thread_path_hash (MuContainer *root, + size_t match_num); /* msg threading algorithm, based on JWZ's algorithm, * http://www.jwz.org/doc/threading.html */ @@ -125,9 +125,8 @@ assert_no_duplicates (GHashTable *ids) } - - -/* a referred message is a message that is refered by some other message */ +/* a referred message is a message that is refered by some other + * message */ static MuContainer* find_or_create_referred (GHashTable *id_table, const char *msgid, gboolean *created) @@ -297,8 +296,7 @@ static GHashTable* create_containers (MuMsgIter *iter) { GHashTable *id_table; - id_table = g_hash_table_new_full (g_str_hash, - g_str_equal, + id_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)mu_container_destroy);