mirror of https://github.com/djcb/mu.git
query-match-deciders: whitespace
This commit is contained in:
parent
c3c8e53454
commit
6caa9acb34
|
@ -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,17 +45,17 @@ 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)
|
||||||
.value_or(*opt_string(doc, MU_MSG_FIELD_ID_PATH))};
|
.value_or (*opt_string (doc, MU_MSG_FIELD_ID_PATH))};
|
||||||
if (!decider_info_.message_ids.emplace(std::move(msgid)).second)
|
if (!decider_info_.message_ids.emplace (std::move (msgid)).second)
|
||||||
qm.flags |= QueryMatch::Flags::Duplicate;
|
qm.flags |= QueryMatch::Flags::Duplicate;
|
||||||
|
|
||||||
const auto path{opt_string(doc, MU_MSG_FIELD_ID_PATH)};
|
const auto path{opt_string (doc, MU_MSG_FIELD_ID_PATH)};
|
||||||
if (!path || ::access(path->c_str(), R_OK) != 0)
|
if (!path || ::access (path->c_str(), R_OK) != 0)
|
||||||
qm.flags |= QueryMatch::Flags::Unreadable;
|
qm.flags |= QueryMatch::Flags::Unreadable;
|
||||||
|
|
||||||
return qm;
|
return qm;
|
||||||
|
@ -68,14 +68,14 @@ 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;
|
||||||
|
|
||||||
if (any_of(qflags_ & QueryFlags::SkipUnreadable) &&
|
if (any_of (qflags_ & QueryFlags::SkipUnreadable) &&
|
||||||
any_of(qm.flags & QueryMatch::Flags::Unreadable))
|
any_of (qm.flags & QueryMatch::Flags::Unreadable))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -86,26 +86,28 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const QueryFlags qflags_;
|
const QueryFlags qflags_;
|
||||||
DeciderInfo& decider_info_;
|
DeciderInfo & decider_info_;
|
||||||
private:
|
|
||||||
Option<std::string> opt_string(const Xapian::Document& doc, MuMsgFieldId id) const noexcept try {
|
private:
|
||||||
auto&& val{doc.get_value(id)};
|
Option<std::string> opt_string (const Xapian::Document &doc, MuMsgFieldId id) const noexcept
|
||||||
return val.empty() ? Nothing : Some(val);
|
try {
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN (Nothing);
|
auto &&val{doc.get_value (id)};
|
||||||
|
return val.empty() ? Nothing : Some (val);
|
||||||
|
}
|
||||||
|
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,32 +134,25 @@ 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)
|
||||||
{
|
{
|
||||||
return std::make_unique<MatchDeciderLeader>(qflags, info);
|
return std::make_unique<MatchDeciderLeader> (qflags, 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,32 +172,31 @@ 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())
|
||||||
return should_include(it->second);
|
return should_include (it->second);
|
||||||
|
|
||||||
auto qm{make_query_match(doc)};
|
auto qm{make_query_match (doc)};
|
||||||
if (should_include(qm)) {
|
if (should_include (qm)) {
|
||||||
qm.flags = QueryMatch::Flags::Related;
|
qm.flags = QueryMatch::Flags::Related;
|
||||||
decider_info_.matches.emplace(doc.get_docid(), std::move(qm));
|
decider_info_.matches.emplace (doc.get_docid(), std::move (qm));
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return false; // nope.
|
return false; // nope.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
return std::make_unique<MatchDeciderRelated>(qflags, info);
|
return std::make_unique<MatchDeciderRelated> (qflags, 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,17 +209,17 @@ 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())};
|
||||||
return it != decider_info_.matches.end() && !it->second.thread_path.empty();
|
return it != decider_info_.matches.end() && !it->second.thread_path.empty();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
return std::make_unique<MatchDeciderThread>(qflags, info);
|
return std::make_unique<MatchDeciderThread> (qflags, info);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue