From 047c10453a48e6638fe04d6fae6725342d8410c0 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 4 Jun 2021 00:44:28 +0300 Subject: [PATCH] query: gather related ids from mset, not match-decider Since we only want the (smaller) set from the mset, not the (full) set that the match-decider sees. --- lib/mu-query-match-deciders.cc | 4 ++-- lib/mu-query.cc | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/mu-query-match-deciders.cc b/lib/mu-query-match-deciders.cc index 9f5a8aeb..b0d07325 100644 --- a/lib/mu-query-match-deciders.cc +++ b/lib/mu-query-match-deciders.cc @@ -140,8 +140,8 @@ struct MatchDeciderLeader final: public MatchDecider { it.first->second.flags |= QueryMatch::Flags::Leader; if (should_include(it.first->second)) { - if (any_of(qflags_ & QueryFlags::GatherThreadIds)) - gather_thread_ids(doc); + // if (any_of(qflags_ & QueryFlags::GatherThreadIds)) + // gather_thread_ids(doc); return true; } return false; diff --git a/lib/mu-query.cc b/lib/mu-query.cc index 9f36e2c2..0a1adb72 100644 --- a/lib/mu-query.cc +++ b/lib/mu-query.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2020 Dirk-Jan C. Binnema +** Copyright (C) 2008-2021 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -175,6 +175,11 @@ Query::Private::run_singular (const std::string& expr, MuMsgFieldId sortfieldid, return threading ? run_threaded(std::move(qres), enq, qflags, maxnum) : qres; } +static Option +opt_string(const Xapian::Document& doc, MuMsgFieldId id) noexcept try { + auto&& val{doc.get_value(id)}; + return val.empty() ? Nothing : Some(val); +} MU_XAPIAN_CATCH_BLOCK_RETURN (Nothing); Option Query::Private::run_related (const std::string& expr, MuMsgFieldId sortfieldid, @@ -196,6 +201,14 @@ Query::Private::run_related (const std::string& expr, MuMsgFieldId sortfieldid, const auto mset{enq.get_mset(0, maxnum, {}, make_leader_decider(leader_qflags, minfo).get())}; + // Gather the thread-ids we found + mset.fetch(); + for (auto it = mset.begin(); it != mset.end(); ++it) { + auto thread_id{opt_string(it.get_document(), MU_MSG_FIELD_ID_THREAD_ID)}; + if (thread_id) + minfo.thread_ids.emplace(std::move(*thread_id)); + } + // Now, determine the "related query". // // In the threaded-case, we search among _all_ messages, since complete @@ -210,6 +223,7 @@ Query::Private::run_related (const std::string& expr, MuMsgFieldId sortfieldid, return threading ? run_threaded(std::move(qres), r_enq, qflags, maxnum) : qres; } + Option Query::Private::run (const std::string& expr, MuMsgFieldId sortfieldid, QueryFlags qflags, size_t maxnum) const