Merge pull request #1284 from nicolasavru/limit-threading-set
Perform threading calculation on related set instead of entire result.
This commit is contained in:
@ -369,15 +369,23 @@ get_related_query (MuMsgIter *iter, GHashTable **orig_set)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
include_related (MuQuery *self, MuMsgIter **iter, int maxnum,
|
get_related_messages (MuQuery *self, MuMsgIter **iter, int maxnum,
|
||||||
MuMsgFieldId sortfieldid, MuQueryFlags flags)
|
MuMsgFieldId sortfieldid, MuQueryFlags flags,
|
||||||
|
Xapian::Query orig_query)
|
||||||
{
|
{
|
||||||
GHashTable *orig_set;
|
GHashTable *orig_set;
|
||||||
Xapian::Enquire enq (self->db());
|
Xapian::Enquire enq (self->db());
|
||||||
MuMsgIter *rel_iter;
|
MuMsgIter *rel_iter;
|
||||||
|
const bool inc_related = flags & MU_QUERY_FLAG_INCLUDE_RELATED;
|
||||||
|
|
||||||
orig_set = NULL;
|
orig_set = NULL;
|
||||||
enq.set_query(get_related_query (*iter, &orig_set));
|
Xapian::Query new_query = get_related_query (*iter, &orig_set);
|
||||||
|
/* If related message are not desired, filter out messages which would not
|
||||||
|
have matched the original query.
|
||||||
|
*/
|
||||||
|
if (!inc_related)
|
||||||
|
new_query = Xapian::Query (Xapian::Query::OP_AND, orig_query, new_query);
|
||||||
|
enq.set_query(new_query);
|
||||||
enq.set_cutoff(0,0);
|
enq.set_cutoff(0,0);
|
||||||
|
|
||||||
rel_iter= mu_msg_iter_new (
|
rel_iter= mu_msg_iter_new (
|
||||||
@ -410,11 +418,12 @@ mu_query_run (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid,
|
|||||||
sortfieldid == MU_MSG_FIELD_ID_NONE,
|
sortfieldid == MU_MSG_FIELD_ID_NONE,
|
||||||
NULL);
|
NULL);
|
||||||
try {
|
try {
|
||||||
MuMsgIter *iter;
|
MuMsgIter *iter;
|
||||||
MuQueryFlags first_flags;
|
MuQueryFlags first_flags;
|
||||||
const auto inc_related = flags & MU_QUERY_FLAG_INCLUDE_RELATED;
|
const bool threads = flags & MU_QUERY_FLAG_THREADS;
|
||||||
const auto descending = flags & MU_QUERY_FLAG_DESCENDING;
|
const bool inc_related = flags & MU_QUERY_FLAG_INCLUDE_RELATED;
|
||||||
const auto raw = flags & MU_QUERY_FLAG_RAW;
|
const bool descending = flags & MU_QUERY_FLAG_DESCENDING;
|
||||||
|
const bool raw = flags & MU_QUERY_FLAG_RAW;
|
||||||
Xapian::Enquire enq (get_enquire(self, searchexpr, sortfieldid,
|
Xapian::Enquire enq (get_enquire(self, searchexpr, sortfieldid,
|
||||||
descending, raw, err));
|
descending, raw, err));
|
||||||
|
|
||||||
@ -426,31 +435,32 @@ mu_query_run (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid,
|
|||||||
|
|
||||||
/* get the 'real' maxnum if it was specified as < 0 */
|
/* 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
|
/* Calculating threads involves two queries, so do the calculation only in
|
||||||
* effort to calculate threads already in the first
|
* the second query instead of in both.
|
||||||
* query since we can do it in the second one
|
|
||||||
*/
|
*/
|
||||||
if (inc_related)
|
if (threads)
|
||||||
first_flags = (MuQueryFlags)(flags & ~MU_QUERY_FLAG_THREADS);
|
first_flags = (MuQueryFlags)(flags & ~MU_QUERY_FLAG_THREADS);
|
||||||
else
|
else
|
||||||
first_flags = flags;
|
first_flags = flags;
|
||||||
|
/* Perform the initial query, returning up to max num results.
|
||||||
iter = mu_msg_iter_new (
|
*/
|
||||||
|
iter = mu_msg_iter_new (
|
||||||
reinterpret_cast<XapianEnquire*>(&enq),
|
reinterpret_cast<XapianEnquire*>(&enq),
|
||||||
maxnum,
|
maxnum,
|
||||||
/* with inc_related, we do the sorting in the
|
sortfieldid,
|
||||||
* second query
|
|
||||||
*/
|
|
||||||
inc_related ? MU_MSG_FIELD_ID_NONE : sortfieldid,
|
|
||||||
msg_iter_flags (first_flags),
|
msg_iter_flags (first_flags),
|
||||||
err);
|
err);
|
||||||
/*
|
/* If we want threads or related messages, find related messages using a
|
||||||
* if we want related messages, do a second query,
|
* second query based on the message ids / refs of the first query's result.
|
||||||
* based on the message ids / refs of the first one
|
* Do this even if we don't want to include related messages in the final
|
||||||
* */
|
* result so we can apply the threading algorithm to the related message set
|
||||||
if (inc_related)
|
* of a maxnum-sized result instead of the unbounded result of the first
|
||||||
include_related (self, &iter, maxnum, sortfieldid,
|
* query. If threads are desired but related message are not, we will remove
|
||||||
flags);
|
* the undesired related messages later.
|
||||||
|
*/
|
||||||
|
if(threads||inc_related)
|
||||||
|
get_related_messages (self, &iter, maxnum, sortfieldid, flags,
|
||||||
|
enq.get_query());
|
||||||
|
|
||||||
if (err && *err && (*err)->code == MU_ERROR_XAPIAN_MODIFIED) {
|
if (err && *err && (*err)->code == MU_ERROR_XAPIAN_MODIFIED) {
|
||||||
g_clear_error (err);
|
g_clear_error (err);
|
||||||
|
|||||||
Reference in New Issue
Block a user