query-match-deciders: mark as leader / related

So we can use that as metadata later
This commit is contained in:
Dirk-Jan C. Binnema
2021-01-29 22:41:59 +02:00
parent ad86e2c4fc
commit fdcbc5257d

View File

@ -61,6 +61,13 @@ struct MatchDecider: public Xapian::MatchDecider {
return qm; return qm;
} }
/**
* Should this message be included in the results?
*
* @param qm a query match
*
* @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) &&
@ -128,14 +135,14 @@ struct MatchDeciderLeader: public MatchDecider {
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
const 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;
if (should_include(it.first->second)) { if (should_include(it.first->second)) {
if (any_of(qflags_ & QueryFlags::GatherThreadIds)) if (any_of(qflags_ & QueryFlags::GatherThreadIds))
gather_thread_ids(doc); gather_thread_ids(doc);
return true; return true;
} }
return false; return false;
} }
}; };
@ -177,15 +184,16 @@ struct MatchDeciderRelated: public MatchDecider {
*/ */
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.
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);
else { // nope; create it.
const auto new_it = decider_info_.matches.emplace( // nope; create it.
auto new_it = decider_info_.matches.emplace(
doc.get_docid(), make_query_match(doc)); doc.get_docid(), make_query_match(doc));
new_it.first->second.flags |= QueryMatch::Flags::Related;
return should_include(new_it.first->second); return should_include(new_it.first->second);
} }
}
}; };