* lib: threading: pre-sort the threaded results, add some more comments

This commit is contained in:
djcb 2012-10-17 17:59:33 +03:00
parent 9dd0e849a6
commit 8ad01e4aa8
4 changed files with 27 additions and 20 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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<XapianEnquire*>(&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;

View File

@ -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);