mu-query: implement mu_query_count_run
To get the number of matches and nothing else.
This commit is contained in:
@ -468,6 +468,39 @@ mu_query_run (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid,
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
mu_query_count_run (MuQuery *self, const char *searchexpr) try
|
||||
{
|
||||
g_return_val_if_fail (self, 0);
|
||||
g_return_val_if_fail (searchexpr, 0);
|
||||
|
||||
// XXX: this _should_ work and be a bit faster, but gives incorrect
|
||||
// results.
|
||||
// find out why.
|
||||
// const auto enq{get_enquire(self, searchexpr,MU_MSG_FIELD_ID_NONE, false, false, NULL)};
|
||||
// auto mset(enq.get_mset(0, self->db().get_doccount()));
|
||||
// mset.fetch();
|
||||
// return mset.size();
|
||||
|
||||
auto msgiter{mu_query_run(self, searchexpr, MU_MSG_FIELD_ID_NONE, -1,
|
||||
MU_QUERY_FLAG_NONE, NULL)};
|
||||
if (!msgiter)
|
||||
return 0;
|
||||
|
||||
size_t num{};
|
||||
while (!mu_msg_iter_is_done(msgiter)) {
|
||||
++num;
|
||||
mu_msg_iter_next(msgiter);
|
||||
}
|
||||
mu_msg_iter_destroy (msgiter);
|
||||
|
||||
return num;
|
||||
|
||||
} MU_XAPIAN_CATCH_BLOCK_RETURN (0);
|
||||
|
||||
|
||||
|
||||
|
||||
char*
|
||||
mu_query_internal_xapian (MuQuery *self, const char *searchexpr, GError **err)
|
||||
{
|
||||
|
||||
@ -75,8 +75,8 @@ typedef enum {
|
||||
} MuQueryFlags;
|
||||
|
||||
/**
|
||||
* run a Xapian query; for the syntax, please refer to the mu-find
|
||||
* manpage, or http://xapian.org/docs/queryparser.html
|
||||
* run a Xapian query; for the syntax, please refer to the mu-query
|
||||
* manpage
|
||||
*
|
||||
* @param self a valid MuQuery instance
|
||||
* @param expr the search expression; use "" to match all messages
|
||||
@ -98,6 +98,18 @@ MuMsgIter* mu_query_run (MuQuery *self, const char* expr,
|
||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
* run a Xapian query to count the number of matches; for the syntax, please
|
||||
* refer to the mu-query manpage
|
||||
*
|
||||
* @param self a valid MuQuery instance
|
||||
* @param expr the search expression; use "" to match all messages
|
||||
*
|
||||
* @return the number of matches
|
||||
*/
|
||||
size_t mu_query_count_run (MuQuery *self, const char *searchexpr);
|
||||
|
||||
|
||||
/**
|
||||
* get Xapian's internal string representation of the query
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user