query-match-deciders: whitespace

This commit is contained in:
Dirk-Jan C. Binnema
2021-06-13 14:01:28 +03:00
parent c3c8e53454
commit 6caa9acb34
2 changed files with 61 additions and 67 deletions

View File

@ -28,16 +28,16 @@ using namespace Mu;
// whether to include them in the results. // whether to include them in the results.
// //
// Note that to include the "related" messages, we need _two_ queries; the first // Note that to include the "related" messages, we need _two_ queries; the first
// one to get the initial matches (called the Leader-Query) and a Related-Query, to get // one to get the initial matches (called the Leader-Query) and a Related-Query,
// the Leader matches + all messages that have a thread-id seen in the Leader // to get the Leader matches + all messages that have a thread-id seen in the
// matches. // Leader matches.
// //
// We use the MatchDecider to gather information and use it for both queries. // We use the MatchDecider to gather information and use it for both queries.
struct MatchDecider : public Xapian::MatchDecider { struct MatchDecider : public Xapian::MatchDecider {
MatchDecider (QueryFlags qflags, DeciderInfo& info): MatchDecider (QueryFlags qflags, DeciderInfo &info) : qflags_{qflags}, decider_info_{info}
qflags_{qflags}, decider_info_{info} {
{} }
/** /**
* Update the match structure with unreadable/duplicate flags * Update the match structure with unreadable/duplicate flags
* *
@ -45,8 +45,8 @@ struct MatchDecider: public Xapian::MatchDecider {
* *
* @return a new QueryMatch object * @return a new QueryMatch object
*/ */
QueryMatch make_query_match (const Xapian::Document& doc) const { QueryMatch make_query_match (const Xapian::Document &doc) const
{
QueryMatch qm{}; QueryMatch qm{};
auto msgid{opt_string (doc, MU_MSG_FIELD_ID_MSGID) auto msgid{opt_string (doc, MU_MSG_FIELD_ID_MSGID)
@ -68,8 +68,8 @@ struct MatchDecider: public Xapian::MatchDecider {
* *
* @return true or false * @return true or false
*/ */
bool should_include (const QueryMatch& qm) const { bool should_include (const QueryMatch &qm) const
{
if (any_of (qflags_ & QueryFlags::SkipDuplicates) && if (any_of (qflags_ & QueryFlags::SkipDuplicates) &&
any_of (qm.flags & QueryMatch::Flags::Duplicate)) any_of (qm.flags & QueryMatch::Flags::Duplicate))
return false; return false;
@ -86,7 +86,8 @@ struct MatchDecider: public Xapian::MatchDecider {
* @param doc the document (message) * @param doc the document (message)
* *
*/ */
void gather_thread_ids(const Xapian::Document& doc) const { void gather_thread_ids (const Xapian::Document &doc) const
{
auto thread_id{opt_string (doc, MU_MSG_FIELD_ID_THREAD_ID)}; auto thread_id{opt_string (doc, MU_MSG_FIELD_ID_THREAD_ID)};
if (thread_id) if (thread_id)
decider_info_.thread_ids.emplace (std::move (*thread_id)); decider_info_.thread_ids.emplace (std::move (*thread_id));
@ -95,17 +96,18 @@ struct MatchDecider: public Xapian::MatchDecider {
protected: protected:
const QueryFlags qflags_; const QueryFlags qflags_;
DeciderInfo & decider_info_; DeciderInfo & decider_info_;
private: private:
Option<std::string> opt_string(const Xapian::Document& doc, MuMsgFieldId id) const noexcept try { Option<std::string> opt_string (const Xapian::Document &doc, MuMsgFieldId id) const noexcept
try {
auto &&val{doc.get_value (id)}; auto &&val{doc.get_value (id)};
return val.empty() ? Nothing : Some (val); return val.empty() ? Nothing : Some (val);
} MU_XAPIAN_CATCH_BLOCK_RETURN (Nothing); }
MU_XAPIAN_CATCH_BLOCK_RETURN (Nothing);
}; };
struct MatchDeciderLeader final : public MatchDecider { struct MatchDeciderLeader final : public MatchDecider {
MatchDeciderLeader (QueryFlags qflags, DeciderInfo& info): MatchDeciderLeader (QueryFlags qflags, DeciderInfo &info) : MatchDecider (qflags, info) {}
MatchDecider(qflags, info)
{}
/** /**
* operator() * operator()
* *
@ -132,23 +134,17 @@ struct MatchDeciderLeader final: public MatchDecider {
* *
* @return true or false * @return true or false
*/ */
bool operator() (const Xapian::Document& doc) const override { bool operator() (const Xapian::Document &doc) const override
{
// by definition, we haven't seen the docid before, // by definition, we haven't seen the docid before,
// so no need to search // so no need to search
auto it = decider_info_.matches.emplace(doc.get_docid(), auto it = decider_info_.matches.emplace (doc.get_docid(), make_query_match (doc));
make_query_match(doc));
it.first->second.flags |= QueryMatch::Flags::Leader; it.first->second.flags |= QueryMatch::Flags::Leader;
if (should_include(it.first->second)) { return should_include (it.first->second);
// if (any_of(qflags_ & QueryFlags::GatherThreadIds))
// gather_thread_ids(doc);
return true;
}
return false;
} }
}; };
std::unique_ptr<Xapian::MatchDecider> std::unique_ptr<Xapian::MatchDecider>
Mu::make_leader_decider (QueryFlags qflags, DeciderInfo &info) Mu::make_leader_decider (QueryFlags qflags, DeciderInfo &info)
{ {
@ -156,8 +152,7 @@ Mu::make_leader_decider (QueryFlags qflags, DeciderInfo& info)
} }
struct MatchDeciderRelated final : public MatchDecider { struct MatchDeciderRelated final : public MatchDecider {
MatchDeciderRelated(QueryFlags qflags, DeciderInfo& info): MatchDeciderRelated (QueryFlags qflags, DeciderInfo &info) : MatchDecider (qflags, info) {}
MatchDecider(qflags, info) {}
/** /**
* operator() * operator()
* *
@ -177,7 +172,8 @@ struct MatchDeciderRelated final: public MatchDecider {
* *
* @return true or false * @return true or false
*/ */
bool operator() (const Xapian::Document& doc) const override { bool operator() (const Xapian::Document &doc) const override
{
// we may have seen this match in the "Leader" query. // we may have seen this match in the "Leader" query.
const auto it = decider_info_.matches.find (doc.get_docid()); const auto it = decider_info_.matches.find (doc.get_docid());
if (it != decider_info_.matches.end()) if (it != decider_info_.matches.end())
@ -193,7 +189,6 @@ struct MatchDeciderRelated final: public MatchDecider {
} }
}; };
std::unique_ptr<Xapian::MatchDecider> std::unique_ptr<Xapian::MatchDecider>
Mu::make_related_decider (QueryFlags qflags, DeciderInfo &info) Mu::make_related_decider (QueryFlags qflags, DeciderInfo &info)
{ {
@ -201,8 +196,7 @@ Mu::make_related_decider (QueryFlags qflags, DeciderInfo& info)
} }
struct MatchDeciderThread final : public MatchDecider { struct MatchDeciderThread final : public MatchDecider {
MatchDeciderThread(QueryFlags qflags, DeciderInfo& info): MatchDeciderThread (QueryFlags qflags, DeciderInfo &info) : MatchDecider{qflags, info} {}
MatchDecider{qflags, info} {}
/** /**
* operator() * operator()
* *
@ -215,7 +209,8 @@ struct MatchDeciderThread final: public MatchDecider {
* *
* @return true or false * @return true or false
*/ */
bool operator() (const Xapian::Document& doc) const override { bool operator() (const Xapian::Document &doc) const override
{
// we may have seen this match in the "Leader" query, // we may have seen this match in the "Leader" query,
// or in the second (unbuounded) related query; // or in the second (unbuounded) related query;
const auto it{decider_info_.matches.find (doc.get_docid())}; const auto it{decider_info_.matches.find (doc.get_docid())};
@ -223,7 +218,6 @@ struct MatchDeciderThread final: public MatchDecider {
} }
}; };
std::unique_ptr<Xapian::MatchDecider> std::unique_ptr<Xapian::MatchDecider>
Mu::make_thread_decider (QueryFlags qflags, DeciderInfo &info) Mu::make_thread_decider (QueryFlags qflags, DeciderInfo &info)
{ {

View File

@ -1,5 +1,5 @@
/* /*
** Copyright (C) 2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2021 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
** This program is free software; you can redistribute it and/or modify it ** 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 the ** under the terms of the GNU General Public License as published by the