dovecot-2.2: fts: Added "doveadm fts lookup" command.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jun 3 20:58:56 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/e222d1265e4e
changeset: 18826:e222d1265e4e
user: Timo Sirainen <tss at iki.fi>
date: Wed Jun 03 23:56:32 2015 +0300
description:
fts: Added "doveadm fts lookup" command.
This is mainly useful for debugging lib-fts. It doesn't perform any of the
lib-fts tokenization / filtering so you can do raw lookups.
diffstat:
src/plugins/fts/Makefile.am | 1 +
src/plugins/fts/doveadm-fts.c | 98 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 0 deletions(-)
diffs (134 lines):
diff -r 576267a41570 -r e222d1265e4e src/plugins/fts/Makefile.am
--- a/src/plugins/fts/Makefile.am Wed Jun 03 22:39:52 2015 +0300
+++ b/src/plugins/fts/Makefile.am Wed Jun 03 23:56:32 2015 +0300
@@ -7,6 +7,7 @@
-I$(top_srcdir)/src/lib-fts \
-I$(top_srcdir)/src/lib-http \
-I$(top_srcdir)/src/lib-mail \
+ -I$(top_srcdir)/src/lib-imap \
-I$(top_srcdir)/src/lib-index \
-I$(top_srcdir)/src/lib-storage \
-I$(top_srcdir)/src/lib-storage/index \
diff -r 576267a41570 -r e222d1265e4e src/plugins/fts/doveadm-fts.c
--- a/src/plugins/fts/doveadm-fts.c Wed Jun 03 22:39:52 2015 +0300
+++ b/src/plugins/fts/doveadm-fts.c Wed Jun 03 23:56:32 2015 +0300
@@ -1,14 +1,111 @@
/* Copyright (c) 2011-2015 Dovecot authors, see the included COPYING file */
#include "lib.h"
+#include "str.h"
+#include "imap-util.h"
#include "mail-namespace.h"
+#include "mail-search.h"
+#include "mailbox-list-iter.h"
#include "fts-storage.h"
#include "doveadm-mail.h"
+#include "doveadm-mailbox-list-iter.h"
#include "doveadm-fts.h"
const char *doveadm_fts_plugin_version = DOVECOT_ABI_VERSION;
static int
+cmd_search_box(struct doveadm_mail_cmd_context *ctx,
+ const struct mailbox_info *info)
+{
+ struct mailbox *box;
+ struct fts_backend *backend;
+ struct fts_result result;
+ int ret = 0;
+
+ backend = fts_list_backend(info->ns->list);
+ if (backend == NULL) {
+ i_error("fts not enabled for %s", info->vname);
+ return -1;
+ }
+
+ memset(&result, 0, sizeof(result));
+ i_array_init(&result.definite_uids, 16);
+ i_array_init(&result.maybe_uids, 16);
+ i_array_init(&result.scores, 16);
+
+ box = mailbox_alloc(info->ns->list, info->vname, 0);
+ if (fts_backend_lookup(backend, box, ctx->search_args->args,
+ FTS_LOOKUP_FLAG_AND_ARGS, &result) < 0) {
+ i_error("fts lookup failed");
+ doveadm_mail_failed_error(ctx, MAIL_ERROR_TEMP);
+ ret = -1;
+ } else {
+ printf("%s: ", info->vname);
+ if (array_count(&result.definite_uids) == 0)
+ printf("no results\n");
+ else T_BEGIN {
+ string_t *str = t_str_new(128);
+ imap_write_seq_range(str, &result.definite_uids);
+ printf("%s\n", str_c(str));
+ } T_END;
+ if (array_count(&result.maybe_uids) > 0) T_BEGIN {
+ string_t *str = t_str_new(128);
+ imap_write_seq_range(str, &result.maybe_uids);
+ printf(" - maybe: %s\n", str_c(str));
+ } T_END;
+ fts_backend_lookup_done(backend);
+ }
+ mailbox_free(&box);
+ array_free(&result.definite_uids);
+ array_free(&result.maybe_uids);
+ array_free(&result.scores);
+ return ret;
+}
+
+static int
+cmd_fts_lookup_run(struct doveadm_mail_cmd_context *ctx,
+ struct mail_user *user)
+{
+ const enum mailbox_list_iter_flags iter_flags =
+ MAILBOX_LIST_ITER_NO_AUTO_BOXES |
+ MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
+ struct doveadm_mailbox_list_iter *iter;
+ const struct mailbox_info *info;
+ int ret = 0;
+
+ iter = doveadm_mailbox_list_iter_init(ctx, user, ctx->search_args,
+ iter_flags);
+ while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) T_BEGIN {
+ if (cmd_search_box(ctx, info) < 0)
+ ret = -1;
+ } T_END;
+ if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
+ ret = -1;
+ return ret;
+}
+
+static void
+cmd_fts_lookup_init(struct doveadm_mail_cmd_context *ctx,
+ const char *const args[])
+{
+ if (args[0] == NULL)
+ doveadm_mail_help_name("fts lookup");
+
+ ctx->search_args = doveadm_mail_build_search_args(args);
+}
+
+static struct doveadm_mail_cmd_context *
+cmd_fts_lookup_alloc(void)
+{
+ struct doveadm_mail_cmd_context *ctx;
+
+ ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
+ ctx->v.run = cmd_fts_lookup_run;
+ ctx->v.init = cmd_fts_lookup_init;
+ return ctx;
+}
+
+static int
fts_namespace_find(struct mail_user *user, const char *ns_prefix,
struct mail_namespace **ns_r)
{
@@ -113,6 +210,7 @@
}
static struct doveadm_mail_cmd fts_commands[] = {
+ { cmd_fts_lookup_alloc, "fts lookup", "<search query>" },
{ cmd_fts_optimize_alloc, "fts optimize", "[<namespace>]" },
{ cmd_fts_rescan_alloc, "fts rescan", "[<namespace>]" }
};
More information about the dovecot-cvs
mailing list