From: Marco Bettini Date: Fri, 17 Dec 2021 08:27:07 +0000 (+0100) Subject: plugins/fts: Allow plugins to carry state across calls during search session X-Git-Tag: 2.3.19~82 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b05ece4965430329d64818113324e1c493e160b;p=thirdparty%2Fdovecot%2Fcore.git plugins/fts: Allow plugins to carry state across calls during search session --- diff --git a/src/plugins/fts/fts-api.h b/src/plugins/fts/fts-api.h index fcf0be3cf3..11a331f8a0 100644 --- a/src/plugins/fts/fts-api.h +++ b/src/plugins/fts/fts-api.h @@ -53,7 +53,24 @@ struct fts_score_map { }; ARRAY_DEFINE_TYPE(fts_score_map, struct fts_score_map); +/* the structure is meant to be implemented by plugins that want to carry + some state over from a call to next ones within an fts_search_context + session. + + The pointer to this structure is initially granted to be NULL and it + remains such unless the plugin itself activates it. + + Any memory management for the pointer and its contents is expected to + be performed by the plugin itself, possibly but not necessarily using + the result pool propagated to plugin call by struct fts_result.pool and + struct fts_multi_result.pool. */ + +struct fts_search_state; + struct fts_result { + pool_t pool; + struct fts_search_state *search_state; + struct mailbox *box; ARRAY_TYPE(seq_range) definite_uids; @@ -67,6 +84,8 @@ struct fts_result { struct fts_multi_result { pool_t pool; + struct fts_search_state *search_state; + /* box=NULL-terminated array of mailboxes and matching UIDs, all allocated from the given pool. */ struct fts_result *box_results; diff --git a/src/plugins/fts/fts-search.c b/src/plugins/fts/fts-search.c index f25078c294..895ea59b6f 100644 --- a/src/plugins/fts/fts-search.c +++ b/src/plugins/fts/fts-search.c @@ -43,6 +43,8 @@ static int fts_search_lookup_level_single(struct fts_search_context *fctx, struct fts_result result; i_zero(&result); + result.search_state = fctx->search_state; + result.pool = fctx->result_pool; p_array_init(&result.definite_uids, fctx->result_pool, 32); p_array_init(&result.maybe_uids, fctx->result_pool, 32); p_array_init(&result.scores, fctx->result_pool, 32); @@ -52,6 +54,7 @@ static int fts_search_lookup_level_single(struct fts_search_context *fctx, &result) < 0) return -1; + fctx->search_state = result.search_state; level = array_append_space(&fctx->levels); level->args_matches = buffer_create_dynamic(fctx->result_pool, 16); fts_search_serialize(level->args_matches, args); @@ -168,6 +171,7 @@ static int fts_search_lookup_level_multi(struct fts_search_context *fctx, array_sort(&mailboxes_arr, mailbox_cmp_fts_backend); i_zero(&result); + result.search_state = fctx->search_state; result.pool = fctx->result_pool; level = array_append_space(&fctx->levels); @@ -197,6 +201,7 @@ static int fts_search_lookup_level_multi(struct fts_search_context *fctx, if (multi_add_lookup_result(fctx, level, args, &result) < 0) return -1; } + fctx->search_state = result.search_state; return 0; } diff --git a/src/plugins/fts/fts-storage.h b/src/plugins/fts/fts-storage.h index 890b8e70b0..ea28ed2596 100644 --- a/src/plugins/fts/fts-storage.h +++ b/src/plugins/fts/fts-storage.h @@ -45,6 +45,7 @@ struct fts_search_context { struct fts_scores *scores; struct fts_indexer_context *indexer_ctx; + struct fts_search_state *search_state; bool virtual_mailbox:1; bool fts_lookup_success:1;