]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: If we haven't indexed all messages, search the rest using non-indexed search.
authorTimo Sirainen <tss@iki.fi>
Wed, 5 Nov 2008 12:37:35 +0000 (14:37 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 5 Nov 2008 12:37:35 +0000 (14:37 +0200)
Typically this happens with header searches which don't force an index update.

--HG--
branch : HEAD

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

index 794c580d64f265902d0ff9d1537c245ca3339056..83732771450ab9296b5a5c28175eab0e595e3af5 100644 (file)
@@ -183,10 +183,12 @@ static int fts_build_init(struct fts_search_context *fctx)
                return -1;
 
        mailbox_get_seq_range(t->box, last_uid+1, (uint32_t)-1, &seq1, &seq2);
+       fctx->first_nonindexed_seq = seq1;
        if (seq1 == 0) {
                /* no new messages */
                return 0;
        }
+
        if (fctx->best_arg->type == SEARCH_HEADER ||
            fctx->best_arg->type == SEARCH_HEADER_COMPRESS_LWSP) {
                /* we're not updating the index just for header lookups */
@@ -202,6 +204,7 @@ static int fts_build_init(struct fts_search_context *fctx)
                last_uid = last_uid_locked;
                mailbox_get_seq_range(t->box, last_uid+1, (uint32_t)-1,
                                      &seq1, &seq2);
+               fctx->first_nonindexed_seq = seq1;
                if (seq1 == 0) {
                        /* no new messages */
                        (void)fts_backend_build_deinit(&build);
@@ -389,9 +392,12 @@ static int fts_mailbox_search_next_nonblock(struct mail_search_context *ctx,
                }
 
                /* finished / error */
-               fts_build_deinit(&fctx->build_ctx);
-               if (ret > 0)
+               if (fts_build_deinit(&fctx->build_ctx) < 0)
+                       ret = -1;
+               if (ret > 0) {
+                       fctx->first_nonindexed_seq = 0;
                        fts_search_lookup(fctx);
+               }
        }
 
        /* if we're here, the indexes are either built or they're not used */
@@ -449,8 +455,13 @@ static int fts_mailbox_search_next_update_seq(struct mail_search_context *ctx)
                /* use whichever is lower of definite/maybe */
                if (fctx->definite_idx == def_count) {
                        if (fctx->maybe_idx == maybe_count) {
-                               /* we're finished */
-                               return 0;
+                               /* look for the non-indexed mails */
+                               if (fctx->first_nonindexed_seq == 0)
+                                       return 0;
+                               fctx->seqs_set = FALSE;
+                               ctx->seq = fctx->first_nonindexed_seq - 1;
+                               return fbox->module_ctx.super.
+                                       search_next_update_seq(ctx);
                        }
                        use_maybe = TRUE;
                } else if (fctx->maybe_idx == maybe_count) {
@@ -505,7 +516,7 @@ static int fts_mailbox_search_deinit(struct mail_search_context *ctx)
 
        if (fctx->build_ctx != NULL) {
                /* the search was cancelled */
-               fts_build_deinit(&fctx->build_ctx);
+               (void)fts_build_deinit(&fctx->build_ctx);
        }
 
        if (array_is_created(&fctx->definite_seqs))
index 29372fcf20504eaf64b4a3599677fa4a59eecd20..ef27aecd49de1649522d2fc63908677280bc0558 100644 (file)
@@ -22,6 +22,7 @@ struct fts_search_context {
        ARRAY_TYPE(seq_range) definite_seqs, maybe_seqs;
        ARRAY_TYPE(fts_score_map) score_map;
        unsigned int definite_idx, maybe_idx;
+       uint32_t first_nonindexed_seq;
 
        struct fts_backend *build_backend;
        struct fts_storage_build_context *build_ctx;