mirror of https://github.com/djcb/mu.git
* implement & use the new batch stuff, small fixes
This commit is contained in:
parent
0a90c0e350
commit
c3b90e6364
61
src/mu-cmd.c
61
src/mu-cmd.c
|
@ -87,34 +87,34 @@ print_query (MuQueryXapian *xapian, const gchar *query)
|
||||||
|
|
||||||
|
|
||||||
static const gchar*
|
static const gchar*
|
||||||
display_field (MuMsgIterXapian *row, const MuMsgField* field)
|
display_field (MuMsgIterXapian *iter, const MuMsgField* field)
|
||||||
{
|
{
|
||||||
gint64 val;
|
gint64 val;
|
||||||
|
|
||||||
switch (mu_msg_field_type(field)) {
|
switch (mu_msg_field_type(field)) {
|
||||||
case MU_MSG_FIELD_TYPE_STRING:
|
case MU_MSG_FIELD_TYPE_STRING:
|
||||||
return mu_msg_iter_xapian_get_field (row, field);
|
return mu_msg_iter_xapian_get_field (iter, field);
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_INT:
|
case MU_MSG_FIELD_TYPE_INT:
|
||||||
|
|
||||||
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_PRIORITY) {
|
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_PRIORITY) {
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (row, field);
|
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_prio ((MuMsgPriority)val);
|
return mu_msg_str_prio ((MuMsgPriority)val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_FLAGS) {
|
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_FLAGS) {
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (row, field);
|
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_flags_s ((MuMsgPriority)val);
|
return mu_msg_str_flags_s ((MuMsgPriority)val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mu_msg_iter_xapian_get_field (row, field); /* as string */
|
return mu_msg_iter_xapian_get_field (iter, field); /* as string */
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_TIME_T:
|
case MU_MSG_FIELD_TYPE_TIME_T:
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (row, field);
|
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_date_s ((time_t)val);
|
return mu_msg_str_date_s ((time_t)val);
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (row, field);
|
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_size_s ((time_t)val);
|
return mu_msg_str_size_s ((time_t)val);
|
||||||
default:
|
default:
|
||||||
g_return_val_if_reached (NULL);
|
g_return_val_if_reached (NULL);
|
||||||
|
@ -142,10 +142,10 @@ sort_field_from_string (const char* fieldstr)
|
||||||
static gboolean
|
static gboolean
|
||||||
print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
MuMsgIterXapian *row;
|
MuMsgIterXapian *iter;
|
||||||
const MuMsgField *sortfield;
|
const MuMsgField *sortfield;
|
||||||
|
|
||||||
MU_WRITE_LOG ("query: '%s' (rows)", query);
|
MU_WRITE_LOG ("query: '%s' (iters)", query);
|
||||||
|
|
||||||
sortfield = NULL;
|
sortfield = NULL;
|
||||||
if (opts->sortfield) {
|
if (opts->sortfield) {
|
||||||
|
@ -154,18 +154,19 @@ print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = mu_query_xapian_run (xapian, query, sortfield,
|
iter = mu_query_xapian_run (xapian, query, sortfield,
|
||||||
!opts->descending);
|
!opts->descending,
|
||||||
if (!row) {
|
10000);
|
||||||
|
if (!iter) {
|
||||||
g_printerr ("error: running query failed\n");
|
g_printerr ("error: running query failed\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (mu_msg_iter_xapian_is_done (row)) {
|
} else if (mu_msg_iter_xapian_is_done (iter)) {
|
||||||
g_printerr ("No matches found\n");
|
g_printerr ("No matches found\n");
|
||||||
mu_msg_iter_xapian_destroy (row);
|
mu_msg_iter_xapian_destroy (iter);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* iterate over the found rows */
|
/* iterate over the found iters */
|
||||||
do {
|
do {
|
||||||
const char* fields = opts->fields;
|
const char* fields = opts->fields;
|
||||||
int printlen = 0;
|
int printlen = 0;
|
||||||
|
@ -180,18 +181,18 @@ print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
||||||
else
|
else
|
||||||
printlen +=
|
printlen +=
|
||||||
printf ("%s",
|
printf ("%s",
|
||||||
display_field(row, field));
|
display_field(iter, field));
|
||||||
++fields;
|
++fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printlen > 0)
|
if (printlen > 0)
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
|
||||||
mu_msg_iter_xapian_next (row);
|
mu_msg_iter_xapian_next (iter);
|
||||||
|
|
||||||
} while (!mu_msg_iter_xapian_is_done (row));
|
} while (!mu_msg_iter_xapian_is_done (iter));
|
||||||
|
|
||||||
mu_msg_iter_xapian_destroy (row);
|
mu_msg_iter_xapian_destroy (iter);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -240,7 +241,7 @@ do_output_links (MuQueryXapian *xapian, MuConfigOptions* opts,
|
||||||
{
|
{
|
||||||
gchar *query;
|
gchar *query;
|
||||||
gboolean retval = TRUE;
|
gboolean retval = TRUE;
|
||||||
MuMsgIterXapian *row;
|
MuMsgIterXapian *iter;
|
||||||
const MuMsgField *pathfield;
|
const MuMsgField *pathfield;
|
||||||
|
|
||||||
if (!create_or_clear_linksdir_maybe (opts))
|
if (!create_or_clear_linksdir_maybe (opts))
|
||||||
|
@ -249,24 +250,25 @@ do_output_links (MuQueryXapian *xapian, MuConfigOptions* opts,
|
||||||
query = mu_query_xapian_combine (params, FALSE);
|
query = mu_query_xapian_combine (params, FALSE);
|
||||||
|
|
||||||
MU_WRITE_LOG ("query: '%s' (links)", query);
|
MU_WRITE_LOG ("query: '%s' (links)", query);
|
||||||
row = mu_query_xapian_run (xapian, query, NULL, FALSE);
|
iter = mu_query_xapian_run (xapian, query, NULL, FALSE, 0);
|
||||||
if (!row) {
|
if (!iter) {
|
||||||
g_printerr ("error: running query failed\n");
|
g_printerr ("error: running query failed\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (mu_msg_iter_xapian_is_done (row)) {
|
} else if (mu_msg_iter_xapian_is_done (iter)) {
|
||||||
g_printerr ("No matches found\n");
|
g_printerr ("No matches found\n");
|
||||||
mu_msg_iter_xapian_destroy (row);
|
mu_msg_iter_xapian_destroy (iter);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pathfield = mu_msg_field_from_id (MU_MSG_FIELD_ID_PATH);
|
pathfield = mu_msg_field_from_id (MU_MSG_FIELD_ID_PATH);
|
||||||
|
|
||||||
/* iterate over the found rows */
|
/* iterate over the found iters */
|
||||||
for (; !mu_msg_iter_xapian_is_done (row); mu_msg_iter_xapian_next (row)) {
|
for (; !mu_msg_iter_xapian_is_done (iter);
|
||||||
|
mu_msg_iter_xapian_next (iter)) {
|
||||||
|
|
||||||
const char *path;
|
const char *path;
|
||||||
|
|
||||||
path = mu_msg_iter_xapian_get_field (row, pathfield);
|
path = mu_msg_iter_xapian_get_field (iter, pathfield);
|
||||||
if (!path)
|
if (!path)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -281,7 +283,7 @@ do_output_links (MuQueryXapian *xapian, MuConfigOptions* opts,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mu_msg_iter_xapian_destroy (row);
|
mu_msg_iter_xapian_destroy (iter);
|
||||||
g_free (query);
|
g_free (query);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -322,7 +324,7 @@ cmd_find (MuConfigOptions *opts)
|
||||||
if (!query_params_valid (opts))
|
if (!query_params_valid (opts))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (mu_util_xapian_db_version_up_to_date (opts->xpath)) {
|
if (!mu_util_xapian_db_version_up_to_date (opts->xpath)) {
|
||||||
update_warning ();
|
update_warning ();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -433,7 +435,6 @@ cmd_index (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
MuIndex *midx;
|
MuIndex *midx;
|
||||||
MuIndexStats stats;
|
MuIndexStats stats;
|
||||||
gboolean reindex;
|
|
||||||
|
|
||||||
mu_index_stats_clear (&stats);
|
mu_index_stats_clear (&stats);
|
||||||
midx = mu_index_new (opts->xpath);
|
midx = mu_index_new (opts->xpath);
|
||||||
|
|
|
@ -181,7 +181,7 @@ mu_config_init (MuConfigOptions *opts, int *argcp, char ***argvp)
|
||||||
{
|
{
|
||||||
gchar *old;
|
gchar *old;
|
||||||
|
|
||||||
g_return_if_fail (opts);
|
g_return_val_if_fail (opts, FALSE);
|
||||||
memset (opts, 0, sizeof(MuConfigOptions));
|
memset (opts, 0, sizeof(MuConfigOptions));
|
||||||
|
|
||||||
/* set dirmode before, because '0000' is a valid mode */
|
/* set dirmode before, because '0000' is a valid mode */
|
||||||
|
|
|
@ -235,7 +235,6 @@ mu_index_run (MuIndex *index, const char* path,
|
||||||
{
|
{
|
||||||
MuIndexCallbackData cb_data;
|
MuIndexCallbackData cb_data;
|
||||||
MuResult rv;
|
MuResult rv;
|
||||||
gchar *version;
|
|
||||||
|
|
||||||
g_return_val_if_fail (index && index->_xapian, MU_ERROR);
|
g_return_val_if_fail (index && index->_xapian, MU_ERROR);
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,8 @@ struct _MuMsgIterXapian {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* FIXME: maybe use get_doccount() on the database object instead
|
|
||||||
* of specifying the batch size? */
|
MuMsgIterXapian*
|
||||||
MuMsgIterXapian *
|
|
||||||
mu_msg_iter_xapian_new (const Xapian::Enquire& enq, size_t batchsize)
|
mu_msg_iter_xapian_new (const Xapian::Enquire& enq, size_t batchsize)
|
||||||
{
|
{
|
||||||
MuMsgIterXapian *iter;
|
MuMsgIterXapian *iter;
|
||||||
|
@ -91,7 +90,18 @@ message_is_readable (MuMsgIterXapian *iter)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MuMsgIterXapian*
|
||||||
|
get_next_batch (MuMsgIterXapian *iter)
|
||||||
|
{
|
||||||
|
iter->_matches = iter->_enq->get_mset (iter->_offset,
|
||||||
|
iter->_batchsize);
|
||||||
|
if (iter->_matches.empty())
|
||||||
|
iter->_cursor = iter->_matches.end();
|
||||||
|
else
|
||||||
|
iter->_cursor = iter->_matches.begin();
|
||||||
|
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_msg_iter_xapian_next (MuMsgIterXapian *iter)
|
mu_msg_iter_xapian_next (MuMsgIterXapian *iter)
|
||||||
|
@ -100,9 +110,12 @@ mu_msg_iter_xapian_next (MuMsgIterXapian *iter)
|
||||||
g_return_val_if_fail (!mu_msg_iter_xapian_is_done(iter), FALSE);
|
g_return_val_if_fail (!mu_msg_iter_xapian_is_done(iter), FALSE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (++iter->_cursor == iter->_matches.end())
|
++iter->_offset;
|
||||||
|
if (++iter->_cursor == iter->_matches.end())
|
||||||
|
iter = get_next_batch (iter);
|
||||||
|
if (iter->_cursor == iter->_matches.end())
|
||||||
return FALSE; /* no more matches */
|
return FALSE; /* no more matches */
|
||||||
|
|
||||||
/* the message may not be readable / existing, e.g., because
|
/* the message may not be readable / existing, e.g., because
|
||||||
* of the database not being fully up to date. in that case,
|
* of the database not being fully up to date. in that case,
|
||||||
* we ignore the message. it might be nice to auto-delete
|
* we ignore the message. it might be nice to auto-delete
|
||||||
|
@ -259,5 +272,6 @@ mu_msg_iter_xapian_get_flags (MuMsgIterXapian *iter)
|
||||||
MuMsgPriority
|
MuMsgPriority
|
||||||
mu_msg_iter_xapian_get_priority (MuMsgIterXapian *iter)
|
mu_msg_iter_xapian_get_priority (MuMsgIterXapian *iter)
|
||||||
{
|
{
|
||||||
return (MuMsgPriority) get_field_number (iter, MU_MSG_FIELD_ID_PRIORITY);
|
return (MuMsgPriority) get_field_number (iter,
|
||||||
|
MU_MSG_FIELD_ID_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue