* mu-query: re-introduce MU_QUERY_FLAG_THREADS, and only calculate threads for

the _second_ query when doing an --include-related query
This commit is contained in:
djcb 2012-12-27 11:09:05 +02:00
parent 99f473945e
commit c6a4e8f9ad
2 changed files with 24 additions and 6 deletions

View File

@ -370,6 +370,8 @@ msg_iter_flags (MuQueryFlags flags)
iflags |= MU_MSG_ITER_FLAG_SKIP_UNREADABLE;
if (flags & MU_QUERY_FLAG_SKIP_DUPS)
iflags |= MU_MSG_ITER_FLAG_SKIP_DUPS;
if (flags & MU_QUERY_FLAG_THREADS)
iflags |= MU_MSG_ITER_FLAG_THREADS;
return iflags;
}
@ -478,23 +480,38 @@ mu_query_run (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid,
NULL);
try {
MuMsgIter *iter;
bool descending = flags & MU_QUERY_FLAG_DESCENDING;
MuQueryFlags first_flags;
bool inc_related = flags & MU_QUERY_FLAG_INCLUDE_RELATED;
bool descending = flags & MU_QUERY_FLAG_DESCENDING;
Xapian::Enquire enq (get_enquire(self, searchexpr, sortfieldid,
descending, err));
/* when we're doing a 'include-related query', we're
* actually doing /two/ queries; one to get the
* initial matches, and based on that one to get all
* messages in threads in those matches.
*/
/* get the 'real' maxnum if it was specified as < 0 */
maxnum = maxnum <= 0 ? self->db().get_doccount() : maxnum;
maxnum = maxnum < 0 ? self->db().get_doccount() : maxnum;
/* if we do a include-related query, it's wasted
* effort to calculate threads already in the first
* query since we can do it in the second one
*/
first_flags = inc_related ? (flags & ~MU_QUERY_FLAG_THREADS) : flags;
iter = mu_msg_iter_new (
reinterpret_cast<XapianEnquire*>(&enq),
maxnum,
sortfieldid,
msg_iter_flags (flags),
msg_iter_flags (first_flags),
err);
/*
* if we want related messages, do a second query,
* based on the message ids / refs of the first one
* */
if (flags & MU_QUERY_FLAG_INCLUDE_RELATED)
if (inc_related)
include_related (self, &iter, maxnum, sortfieldid, flags);
if (err && *err && (*err)->code == MU_ERROR_XAPIAN_MODIFIED) {

View File

@ -71,9 +71,10 @@ enum _MuQueryFlags {
MU_QUERY_FLAG_DESCENDING = 1 << 0, /**< sort z->a */
MU_QUERY_FLAG_SKIP_UNREADABLE = 1 << 1, /**< skip unreadable msgs */
MU_QUERY_FLAG_SKIP_DUPS = 1 << 2, /**< skip duplicate msgs */
MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 3 /**< include related msgs */
MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 3, /**< include related msgs */
MU_QUERY_FLAG_THREADS = 1 << 4 /**< calculate threading info */
};
typedef enum _MuQueryFlags MuQueryFlags;
typedef int MuQueryFlags;
/**
* run a Xapian query; for the syntax, please refer to the mu-find