]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: Added "doveadm fts expand" to show lib-fts search query expanded.
authorTimo Sirainen <tss@iki.fi>
Wed, 3 Jun 2015 21:45:11 +0000 (00:45 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 3 Jun 2015 21:45:11 +0000 (00:45 +0300)
src/plugins/fts/doveadm-fts.c

index 00406b1efe55a366583e0c6da82ad5abe886b707..c6ae537c438f347602023239e9fccda4ff175133 100644 (file)
@@ -7,6 +7,7 @@
 #include "mail-search.h"
 #include "mailbox-list-iter.h"
 #include "fts-storage.h"
+#include "fts-search-args.h"
 #include "doveadm-mail.h"
 #include "doveadm-mailbox-list-iter.h"
 #include "doveadm-fts.h"
@@ -105,6 +106,53 @@ cmd_fts_lookup_alloc(void)
        return ctx;
 }
 
+static int
+cmd_fts_expand_run(struct doveadm_mail_cmd_context *ctx,
+                  struct mail_user *user)
+{
+       struct mail_namespace *ns = mail_namespace_find_inbox(user->namespaces);
+       struct mailbox *box;
+       struct fts_backend *backend;
+       string_t *str = t_str_new(128);
+
+       backend = fts_list_backend(ns->list);
+       if (backend == NULL) {
+               i_error("fts not enabled for INBOX");
+               return -1;
+       }
+
+       box = mailbox_alloc(ns->list, "INBOX", 0);
+       mail_search_args_init(ctx->search_args, box, FALSE, NULL);
+
+       if (fts_search_args_expand(backend, ctx->search_args) < 0)
+               i_fatal("Couldn't expand search args");
+       mail_search_args_to_cmdline(str, ctx->search_args->args);
+       printf("%s\n", str_c(str));
+       mailbox_free(&box);
+       return 0;
+}
+
+static void
+cmd_fts_expand_init(struct doveadm_mail_cmd_context *ctx,
+                   const char *const args[])
+{
+       if (args[0] == NULL)
+               doveadm_mail_help_name("fts expand");
+
+       ctx->search_args = doveadm_mail_build_search_args(args);
+}
+
+static struct doveadm_mail_cmd_context *
+cmd_fts_expand_alloc(void)
+{
+       struct doveadm_mail_cmd_context *ctx;
+
+       ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
+       ctx->v.run = cmd_fts_expand_run;
+       ctx->v.init = cmd_fts_expand_init;
+       return ctx;
+}
+
 static int
 fts_namespace_find(struct mail_user *user, const char *ns_prefix,
                   struct mail_namespace **ns_r)
@@ -211,6 +259,7 @@ cmd_fts_rescan_alloc(void)
 
 static struct doveadm_mail_cmd fts_commands[] = {
        { cmd_fts_lookup_alloc, "fts lookup", "<search query>" },
+       { cmd_fts_expand_alloc, "fts expand", "<search query>" },
        { cmd_fts_optimize_alloc, "fts optimize", "[<namespace>]" },
        { cmd_fts_rescan_alloc, "fts rescan", "[<namespace>]" }
 };