mirror of https://github.com/djcb/mu.git
* <many>: add possibility to limit max number of search results
This commit is contained in:
parent
df35498e13
commit
8bc4d3c113
|
@ -129,7 +129,7 @@ run_query (MuQuery *xapian, const gchar *query, MuConfig *opts,
|
|||
}
|
||||
|
||||
iter = mu_query_run (xapian, query, opts->threads, sortid,
|
||||
opts->reverse, err);
|
||||
opts->reverse, -1, err);
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ install_sig_handler (void)
|
|||
}
|
||||
|
||||
|
||||
/* BOX - beginning-of-expression */
|
||||
#define BOX "\376"
|
||||
|
||||
static void send_expr (const char* frm, ...) G_GNUC_PRINTF(1, 2);
|
||||
|
@ -310,19 +311,29 @@ cmd_info (MuStore *store, GSList *lst, GError **err)
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* find <query> <maxnum>
|
||||
* => list of s-expression, each describing a message
|
||||
* => (:found <number of found messages>)
|
||||
*/
|
||||
static MuError
|
||||
cmd_find (MuStore *store, MuQuery *query, GSList *lst, GError **err)
|
||||
{
|
||||
MuMsgIter *iter;
|
||||
unsigned u;
|
||||
int maxnum;
|
||||
|
||||
if (!check_param_num (lst, 1, 1))
|
||||
if (!check_param_num (lst, 2, 2))
|
||||
return server_error (NULL, MU_ERROR_IN_PARAMETERS,
|
||||
"usage: find <searchexpr>");
|
||||
"usage: find <searchexpr> <maxnum>");
|
||||
|
||||
maxnum = atoi((const char*)lst->next->data);
|
||||
if (maxnum == 0)
|
||||
return server_error (NULL, MU_ERROR_IN_PARAMETERS,
|
||||
"usage: find <maxnum> <searchexpr>");
|
||||
|
||||
iter = mu_query_run (query, (const char*)lst->data, TRUE,
|
||||
MU_MSG_FIELD_ID_DATE, TRUE, err);
|
||||
MU_MSG_FIELD_ID_DATE, TRUE, maxnum, err);
|
||||
if (!iter)
|
||||
return server_error (err, MU_ERROR_INTERNAL,
|
||||
"couldn't get iterator");
|
||||
|
@ -376,7 +387,7 @@ get_docid_from_msgid (MuQuery *query, const char *str, GError **err)
|
|||
|
||||
querystr = g_strdup_printf ("msgid:%s", str);
|
||||
iter = mu_query_run (query, querystr, FALSE,
|
||||
MU_MSG_FIELD_ID_NONE, FALSE, err);
|
||||
MU_MSG_FIELD_ID_NONE, FALSE, 1, err);
|
||||
g_free (querystr);
|
||||
docid = MU_STORE_INVALID_DOCID;
|
||||
if (!iter || mu_msg_iter_is_done (iter))
|
||||
|
@ -464,7 +475,8 @@ do_move (MuStore *store, unsigned docid, MuMsg *msg, const char *maildir,
|
|||
* wel */
|
||||
rv = mu_store_update_msg (store, docid, msg, err);
|
||||
if (rv == MU_STORE_INVALID_DOCID)
|
||||
return server_error (err, MU_ERROR_XAPIAN, "failed to update message");
|
||||
return server_error (err, MU_ERROR_XAPIAN,
|
||||
"failed to update message");
|
||||
|
||||
sexp = mu_msg_to_sexp (msg, docid, NULL, TRUE);
|
||||
send_expr ("(:update %s :move %s)", sexp, is_move ? "t" : "nil");
|
||||
|
|
|
@ -307,7 +307,7 @@ mu_query_preprocess (const char *query)
|
|||
|
||||
MuMsgIter*
|
||||
mu_query_run (MuQuery *self, const char* searchexpr, gboolean threads,
|
||||
MuMsgFieldId sortfieldid, gboolean revert,
|
||||
MuMsgFieldId sortfieldid, gboolean revert, int maxnum,
|
||||
GError **err)
|
||||
{
|
||||
g_return_val_if_fail (self, NULL);
|
||||
|
@ -333,7 +333,8 @@ mu_query_run (MuQuery *self, const char* searchexpr, gboolean threads,
|
|||
|
||||
return mu_msg_iter_new (
|
||||
(XapianEnquire*)&enq,
|
||||
self->db().get_doccount(), threads,
|
||||
maxnum <= 0 ? self->db().get_doccount() : maxnum,
|
||||
threads,
|
||||
threads ? sortfieldid : MU_MSG_FIELD_ID_NONE,
|
||||
revert);
|
||||
|
||||
|
|
|
@ -75,6 +75,8 @@ char* mu_query_version (MuQuery *store)
|
|||
* sorting is not desired
|
||||
* @param reverse if TRUE, sort in descending (Z-A) order, otherwise,
|
||||
* sort in descending (A-Z) order
|
||||
* @param maxnum maximum number of search results to return, or <= 0 for
|
||||
* unlimited
|
||||
* @param err receives error information (if there is any); if
|
||||
* function returns non-NULL, err will _not_be set. err can be NULL
|
||||
* possible error (err->code) is MU_ERROR_QUERY,
|
||||
|
@ -83,7 +85,7 @@ char* mu_query_version (MuQuery *store)
|
|||
* case of error
|
||||
*/
|
||||
MuMsgIter* mu_query_run (MuQuery *self, const char* expr, gboolean threads,
|
||||
MuMsgFieldId sortfieldid, gboolean ascending,
|
||||
MuMsgFieldId sortfieldid, gboolean ascending, int maxnum,
|
||||
GError **err)
|
||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ run_and_count_matches (const char *xpath, const char *query)
|
|||
}
|
||||
|
||||
iter = mu_query_run (mquery, query, FALSE, MU_MSG_FIELD_ID_NONE,
|
||||
FALSE, NULL);
|
||||
FALSE, -1, NULL);
|
||||
mu_query_destroy (mquery);
|
||||
g_assert (iter);
|
||||
|
||||
|
@ -278,7 +278,7 @@ test_mu_query_accented_chars_01 (void)
|
|||
mu_store_unref (store);
|
||||
|
||||
iter = mu_query_run (query, "fünkÿ", FALSE, MU_MSG_FIELD_ID_NONE,
|
||||
FALSE, NULL);
|
||||
FALSE, -1, NULL);
|
||||
err = NULL;
|
||||
msg = mu_msg_iter_get_msg_floating (iter); /* don't unref */
|
||||
if (!msg) {
|
||||
|
|
|
@ -71,7 +71,7 @@ run_and_get_iter (const char *xpath, const char *query)
|
|||
g_assert (query);
|
||||
|
||||
iter = mu_query_run (mquery, query, TRUE, MU_MSG_FIELD_ID_DATE,
|
||||
FALSE, NULL);
|
||||
FALSE, -1, NULL);
|
||||
mu_query_destroy (mquery);
|
||||
g_assert (iter);
|
||||
|
||||
|
@ -244,4 +244,3 @@ main (int argc, char *argv[])
|
|||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue