fts-storage.c revision fe3f637ef0b9544a567b54f3743cf8e3649d8d0f
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2006-2015 Dovecot authors, see the included COPYING file */
02aedbc20af0160091670233383d228f10b168afTimo Sirainen#define INDEXER_HANDSHAKE "VERSION\tindexer\t1\t0\n"
02aedbc20af0160091670233383d228f10b168afTimo Sirainen struct fts_backend_update_context *update_ctx;
02aedbc20af0160091670233383d228f10b168afTimo Sirainen struct fts_backend_update_context *sync_update_ctx;
02aedbc20af0160091670233383d228f10b168afTimo Sirainen union mailbox_transaction_module_context module_ctx;
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(fts_storage_module,
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(fts_mail_module, &mail_module_register);
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(fts_mailbox_list_module,
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainenstatic int fts_mailbox_get_last_cached_seq(struct mailbox *box, uint32_t *seq_r)
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainen struct fts_mailbox_list *flist = FTS_LIST_CONTEXT(box->list);
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainen if (fts_backend_get_last_uid(flist->backend, box, &last_uid) < 0) {
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainen mail_storage_set_internal_error(box->storage);
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainen mailbox_get_seq_range(box, 1, last_uid, &seq1, &seq2);
adad68df4602d80639d7f28e4c7550fbafbd8d60Timo Sirainenfts_mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
02aedbc20af0160091670233383d228f10b168afTimo Sirainen if (fbox->module_ctx.super.get_status(box, items, status_r) < 0)
02aedbc20af0160091670233383d228f10b168afTimo Sirainen if (fts_mailbox_get_last_cached_seq(box, &seq) < 0)
02aedbc20af0160091670233383d228f10b168afTimo Sirainen /* use whichever is smaller */
02aedbc20af0160091670233383d228f10b168afTimo Sirainenstatic void fts_scores_unref(struct fts_scores **_scores)
02aedbc20af0160091670233383d228f10b168afTimo Sirainenstatic void fts_try_build_init(struct mail_search_context *ctx,
02aedbc20af0160091670233383d228f10b168afTimo Sirainen i_assert(!fts_backend_is_updating(fctx->backend));
02aedbc20af0160091670233383d228f10b168afTimo Sirainen ret = fts_indexer_init(fctx->backend, ctx->transaction->box,
02aedbc20af0160091670233383d228f10b168afTimo Sirainen /* the index was up to date */
02aedbc20af0160091670233383d228f10b168afTimo Sirainen /* hide "searching" notifications while building index */
ac1118842c3d80285e32d2cd53bda3e95e5be217Timo Sirainenstatic bool fts_want_build_args(const struct mail_search_arg *args)
02aedbc20af0160091670233383d228f10b168afTimo Sirainen /* we want to update index only when searching from message body.
75af6e5ca2c4685e2316d27364ac7b00def7fed7Timo Sirainen it's not worth the wait for searching only from headers, which
02aedbc20af0160091670233383d228f10b168afTimo Sirainen could be in cache file already */
75af6e5ca2c4685e2316d27364ac7b00def7fed7Timo Sirainenstatic bool fts_args_have_fuzzy(const struct mail_search_arg *args)
76537b1991e7815c7a867a997f7fa2b3c17412d4Aki Tuomifts_mailbox_search_init(struct mailbox_transaction_context *t,
9fc9965693110c250c6d6aa36ab60a77c934cc49Timo Sirainen struct fts_transaction_context *ft = FTS_CONTEXT(t);
76537b1991e7815c7a867a997f7fa2b3c17412d4Aki Tuomi struct fts_mailbox_list *flist = FTS_LIST_CONTEXT(t->box->list);
02aedbc20af0160091670233383d228f10b168afTimo Sirainen ctx = fbox->module_ctx.super.search_init(t, args, sort_program,
02aedbc20af0160091670233383d228f10b168afTimo Sirainen if (!fts_backend_can_lookup(flist->backend, args->args))
02aedbc20af0160091670233383d228f10b168afTimo Sirainen fctx->result_pool = pool_alloconly_create("fts results", 1024*64);
02aedbc20af0160091670233383d228f10b168afTimo Sirainen fctx->orig_matches = buffer_create_dynamic(default_pool, 64);
02aedbc20af0160091670233383d228f10b168afTimo Sirainen strcmp(t->box->storage->name, VIRTUAL_STORAGE_NAME) == 0;
02aedbc20af0160091670233383d228f10b168afTimo Sirainen mail_user_plugin_getenv(t->box->storage->user,
return ctx;
int ret;
if (ret == 0)
return FALSE;
if (ret > 0)
if (ret < 0) {
return TRUE;
return FALSE;
return FALSE;
return FALSE;
return FALSE;
unsigned int idx;
return FALSE;
return FALSE;
return TRUE;
idx = 0;
return TRUE;
int ret = 0;
return ret;
const char **value_r)
int ret = 0;
return ret;
} else T_BEGIN {
} T_END;
static struct mailbox_transaction_context *
struct mailbox_transaction_context *t;
return ret;
(void)fts_transaction_end(t);
unsigned int max_recent_msgs;
int fd;
max_recent_msgs = 0;
bool autoindex;
int ret = 0;
if (fts_transaction_end(t) < 0) {
if (ret < 0)
if (autoindex)
bool optimize;
int ret = 0;
MAILBOX_SYNC_FLAG_OPTIMIZE)) != 0;
if (optimize) {
return ret;
const char *name;