query-results: remove GatherThreadIds

We can't really do that in the match-decider, since we get _all_ messages
there, not the <n>-limited.

And some whitespace changes.
This commit is contained in:
Dirk-Jan C. Binnema
2021-06-13 18:36:24 +03:00
parent 6caa9acb34
commit 619509eb56
3 changed files with 136 additions and 131 deletions

View File

@ -39,7 +39,8 @@
#include "mu-msg.hh"
namespace Mu {
namespace Mu
{
/**
* This implements a QueryResults structure, which capture the results of a
@ -59,12 +60,9 @@ enum struct QueryFlags {
// internal
Leader = 1 << 5, /**< This is the leader query (for internal use
* only)*/
GatherThreadIds = 1 << 6, /**< Gather thread info */
};
MU_ENABLE_BITOPS (QueryFlags);
/// Stores all the essential information for sorting the results.
struct QueryMatch {
/// Flags for a match (message) found
@ -96,9 +94,7 @@ struct QueryMatch {
std::string thread_path; /**< The hex-numerial path in the thread, ie. '00:01:0a' */
std::string thread_date; /**< date of newest message in thread */
bool operator<(const QueryMatch& rhs) const {
return date_key < rhs.date_key;
}
bool operator< (const QueryMatch &rhs) const { return date_key < rhs.date_key; }
bool has_flag (Flags flag) const;
};
@ -111,7 +107,6 @@ QueryMatch::has_flag(QueryMatch::Flags flag) const
return any_of (flags & flag);
}
inline std::ostream &
operator<< (std::ostream &os, QueryMatch::Flags mflags)
{
@ -143,7 +138,6 @@ operator<<(std::ostream& os, QueryMatch::Flags mflags)
return os;
}
using QueryMatches = std::unordered_map<Xapian::docid, QueryMatch>;
inline std::ostream &
@ -163,7 +157,8 @@ operator<<(std::ostream& os, const QueryMatch& qmatch)
/// Note, we internally skip unreadable/duplicate messages (when asked too); those
/// skipped ones do _not_ count towards the max_size
///
class QueryResultsIterator {
class QueryResultsIterator
{
public:
using iterator_category = std::output_iterator_tag;
using value_type = MuMsg *;
@ -171,18 +166,22 @@ public:
using pointer = void;
using reference = void;
QueryResultsIterator(Xapian::MSetIterator mset_it, QueryMatches& query_matches):
mset_it_{mset_it}, query_matches_{query_matches}
{}
QueryResultsIterator (Xapian::MSetIterator mset_it, QueryMatches &query_matches)
: mset_it_{mset_it}, query_matches_{query_matches}
{
}
~QueryResultsIterator() { g_clear_pointer (&msg_, mu_msg_unref); }
/**
* Increment the iterator (we don't support post-increment)
*
* @return an updated iterator, or end() if we were already at end()
*/
QueryResultsIterator& operator++() { ++mset_it_; return *this; }
QueryResultsIterator &operator++()
{
++mset_it_;
return *this;
}
/**
* (Non)Equivalence operators
@ -219,7 +218,10 @@ public:
*
* @return a message-id
*/
Option<std::string> message_id() const noexcept { return opt_string(MU_MSG_FIELD_ID_MSGID); }
Option<std::string> message_id() const noexcept
{
return opt_string (MU_MSG_FIELD_ID_MSGID);
}
/**
* Get the thread-id for the document (message) this iterator is
@ -227,7 +229,10 @@ public:
*
* @return a message-id
*/
Option<std::string> thread_id() const noexcept { return opt_string(MU_MSG_FIELD_ID_THREAD_ID); }
Option<std::string> thread_id() const noexcept
{
return opt_string (MU_MSG_FIELD_ID_THREAD_ID);
}
/**
* Get the file-system path for the document (message) this iterator is
@ -251,8 +256,10 @@ public:
*
* @return the subject
*/
Option<std::string> subject() const noexcept { return opt_string(MU_MSG_FIELD_ID_SUBJECT); }
Option<std::string> subject() const noexcept
{
return opt_string (MU_MSG_FIELD_ID_SUBJECT);
}
/**
* Get the references for the document (messages) this is iterator is
@ -261,7 +268,8 @@ public:
*
* @return references
*/
std::vector<std::string> references() const noexcept {
std::vector<std::string> references() const noexcept
{
return split (document().get_value (MU_MSG_FIELD_ID_REFS), ",");
}
@ -272,21 +280,25 @@ public:
*
* @return the value
*/
Option<std::string> opt_string(MuMsgFieldId id) const noexcept try {
Option<std::string> opt_string (MuMsgFieldId id) const noexcept
try {
auto &&val{document().get_value (id)};
return val.empty() ? Nothing : Some (val);
} MU_XAPIAN_CATCH_BLOCK_RETURN (Nothing);
}
MU_XAPIAN_CATCH_BLOCK_RETURN (Nothing);
/**
* Get the Query match info for this message.
*
* @return the match info.
*/
QueryMatch& query_match() {
QueryMatch &query_match()
{
g_assert (query_matches_.find (document().get_docid()) != query_matches_.end());
return query_matches_.find (document().get_docid())->second;
}
const QueryMatch& query_match() const {
const QueryMatch &query_match() const
{
g_assert (query_matches_.find (document().get_docid()) != query_matches_.end());
return query_matches_.find (document().get_docid())->second;
}
@ -298,10 +310,9 @@ k * destroyed.; it's a 'floating' reference.
*
* @return a MuMsg* or NUL in case of error
*/
MuMsg* floating_msg ()
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT try {
auto docp{reinterpret_cast<XapianDocument*>(
new Xapian::Document(document()))};
MuMsg *floating_msg() G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
try {
auto docp{reinterpret_cast<XapianDocument *> (new Xapian::Document (document()))};
GError *err{};
g_clear_pointer (&msg_, mu_msg_unref);
if (!(msg_ = mu_msg_new_from_doc (docp, &err))) {
@ -313,8 +324,9 @@ k * destroyed.; it's a 'floating' reference.
}
return msg_;
}
MU_XAPIAN_CATCH_BLOCK_RETURN (NULL);
} MU_XAPIAN_CATCH_BLOCK_RETURN (NULL);
private:
Xapian::MSetIterator mset_it_;
QueryMatches & query_matches_;
@ -323,7 +335,8 @@ private:
constexpr auto MaxQueryResultsSize = std::numeric_limits<size_t>::max();
class QueryResults {
class QueryResults
{
public:
/// Helper types
using iterator = QueryResultsIterator;
@ -334,10 +347,10 @@ public:
*
* @param mset an Xapian::MSet with matches
*/
QueryResults (const Xapian::MSet& mset, QueryMatches&& query_matches):
mset_{mset},
query_matches_{std::move(query_matches)}
{}
QueryResults (const Xapian::MSet &mset, QueryMatches &&query_matches)
: mset_{mset}, query_matches_{std::move (query_matches)}
{
}
/**
* Is this QueryResults object empty (ie., no matches)?
*
@ -357,10 +370,9 @@ public:
*
* @return iterator
*/
iterator begin() {
return QueryResultsIterator(mset_.begin(), query_matches_);
}
const iterator begin() const {
iterator begin() { return QueryResultsIterator (mset_.begin(), query_matches_); }
const iterator begin() const
{
return QueryResultsIterator (mset_.begin(), query_matches_);
}
@ -369,12 +381,8 @@ public:
*
* @return iterator
*/
iterator end() {
return QueryResultsIterator(mset_.end(), query_matches_);
}
const_iterator end() const {
return QueryResultsIterator(mset_.end(), query_matches_);
}
iterator end() { return QueryResultsIterator (mset_.end(), query_matches_); }
const_iterator end() const { return QueryResultsIterator (mset_.end(), query_matches_); }
/**
* Get the query-matches for these QueryResults. The non-const
@ -393,5 +401,4 @@ private:
} // namespace Mu
#endif /* MU_QUERY_RESULTS_HH__ */

View File

@ -192,7 +192,7 @@ Query::Private::run_related (const std::string& expr, MuMsgFieldId sortfieldid,
// moreover, in either threaded or non-threaded case, we sort the first
// ("leader") query by date, i.e, we prefer the newest or oldest
// (descending) messages.
const auto leader_qflags{QueryFlags::Leader | QueryFlags::GatherThreadIds};
const auto leader_qflags{QueryFlags::Leader};
const auto threading{any_of(qflags & QueryFlags::Threading)};
// Run our first, "leader" query
@ -247,7 +247,6 @@ Query::run (const std::string& expr, MuMsgFieldId sortfieldid,
{
// some flags are for internal use only.
g_return_val_if_fail (none_of(qflags & QueryFlags::Leader), Nothing);
g_return_val_if_fail (none_of(qflags & QueryFlags::GatherThreadIds), Nothing);
StopWatch sw{format("ran query '%s'; related: %s; threads: %s; max-size: %zu",
expr.c_str(),

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2021 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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
@ -27,10 +27,11 @@
#include <mu-query-results.hh>
#include <utils/mu-utils.hh>
namespace Mu
{
namespace Mu {
class Query {
class Query
{
public:
/**
* Construct a new Query instance.
@ -44,7 +45,6 @@ public:
*/
~Query();
/**
* Move CTOR
*
@ -64,8 +64,7 @@ public:
*/
Option<QueryResults> run (const std::string &expr = "",
MuMsgFieldId sortfieldid = MU_MSG_FIELD_ID_NONE,
QueryFlags flags=QueryFlags::None,
size_t maxnum=0) const;
QueryFlags flags = QueryFlags::None, size_t maxnum = 0) const;
/**
* run a Xapian query to count the number of matches; for the syntax, please
@ -88,11 +87,11 @@ public:
* @return the string representation of the query
*/
std::string parse (const std::string &expr, bool xapian) const;
private:
struct Private;
std::unique_ptr<Private> priv_;
};
}
} // namespace Mu
#endif /*__MU_QUERY_HH__*/