]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: Add fts_enforced=body
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 20 May 2018 09:27:22 +0000 (12:27 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 28 Mar 2019 06:37:10 +0000 (06:37 +0000)
Similar to "no", this doesn't enforce FTS indexing for header searches.
Similar to "yes", on FTS lookup failure it won't fallback to reading all
mails.

src/plugins/fts/fts-storage.c
src/plugins/fts/fts-storage.h

index fe72ad8b5aa539a77fc5c957b09ed6fd30bf7f54..2cecce864f1653adba3fc51f5c1949c182df03fb 100644 (file)
@@ -195,6 +195,16 @@ static bool fts_args_have_fuzzy(const struct mail_search_arg *args)
        return FALSE;
 }
 
+static enum fts_enforced fts_enforced_parse(const char *str)
+{
+       if (str == NULL || strcmp(str, "no") == 0)
+               return FTS_ENFORCED_NO;
+       else if (strcmp(str, "body") == 0)
+               return FTS_ENFORCED_BODY;
+       else
+               return FTS_ENFORCED_YES;
+}
+
 static struct mail_search_context *
 fts_mailbox_search_init(struct mailbox_transaction_context *t,
                        struct mail_search_args *args,
@@ -222,9 +232,8 @@ fts_mailbox_search_init(struct mailbox_transaction_context *t,
        fctx->result_pool = pool_alloconly_create("fts results", 1024*64);
        fctx->orig_matches = buffer_create_dynamic(default_pool, 64);
        fctx->virtual_mailbox = t->box->virtual_vfuncs != NULL;
-       fctx->enforced =
-               mail_user_plugin_getenv_bool(t->box->storage->user,
-                                       "fts_enforced");
+       fctx->enforced = fts_enforced_parse(
+               mail_user_plugin_getenv(t->box->storage->user, "fts_enforced"));
        i_array_init(&fctx->levels, 8);
        fctx->scores = i_new(struct fts_scores, 1);
        fctx->scores->refcount = 1;
@@ -244,7 +253,8 @@ fts_mailbox_search_init(struct mailbox_transaction_context *t,
        ft->scores = fctx->scores;
        ft->scores->refcount++;
 
-       if (fctx->enforced || fts_want_build_args(args->args))
+       if (fctx->enforced == FTS_ENFORCED_YES ||
+           fts_want_build_args(args->args))
                fts_try_build_init(ctx, fctx);
        else
                fts_search_lookup(fctx);
@@ -305,7 +315,8 @@ fts_mailbox_search_next_nonblock(struct mail_search_context *ctx,
                        return FALSE;
                }
        }
-       if (fctx != NULL && !fctx->fts_lookup_success && fctx->enforced)
+       if (fctx != NULL && !fctx->fts_lookup_success &&
+           fctx->enforced != FTS_ENFORCED_NO)
                return FALSE;
 
        return fbox->module_ctx.super.
@@ -381,7 +392,8 @@ static int fts_mailbox_search_deinit(struct mail_search_context *ctx)
                }
                if (fctx->indexing_timed_out)
                        ret = -1;
-               if (!fctx->fts_lookup_success && fctx->enforced) {
+               if (!fctx->fts_lookup_success &&
+                   fctx->enforced != FTS_ENFORCED_NO) {
                        /* FTS lookup failed and we didn't want to fallback to
                           opening all the mails and searching manually */
                        mail_storage_set_internal_error(ctx->transaction->box->storage);
index 3b7f11721286392168968a57ced85af87ddfbdea..3776dddf6abc585750d760033da955ff4424dd78 100644 (file)
@@ -4,6 +4,12 @@
 #include "mail-storage-private.h"
 #include "fts-api.h"
 
+enum fts_enforced {
+       FTS_ENFORCED_NO,
+       FTS_ENFORCED_YES,
+       FTS_ENFORCED_BODY,
+};
+
 struct fts_scores {
        int refcount;
        ARRAY_TYPE(fts_score_map) score_map;
@@ -23,6 +29,7 @@ struct fts_search_context {
        struct mailbox_transaction_context *t;
        struct mail_search_args *args;
        enum fts_lookup_flags flags;
+       enum fts_enforced enforced;
 
        pool_t result_pool;
        ARRAY(struct fts_search_level) levels;
@@ -38,7 +45,6 @@ struct fts_search_context {
        bool virtual_mailbox:1;
        bool fts_lookup_success:1;
        bool indexing_timed_out:1;
-       bool enforced:1;
 };
 
 /* Figure out if we want to use full text search indexes and update