fts-backend-squat.c revision 4ae81f8f7aad06aad2f570535cad6e40aaec2b28
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#define SQUAT_FILE_PREFIX "dovecot.index.search"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_set(struct squat_fts_backend *backend, const char *str)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch const char *const *tmp;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch for (tmp = t_strsplit_spaces(str, " "); *tmp != NULL; tmp++) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch squat_trie_set_partial_len(backend->trie, len);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_fatal("fts_squat: Invalid setting: %s", *tmp);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic struct fts_backend *fts_backend_squat_init(struct mailbox *box)
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch path = mail_storage_get_mailbox_index_dir(storage,
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch /* in-memory indexes */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch mailbox_get_status(box, STATUS_UIDVALIDITY, &status);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if ((storage->flags & (MAIL_STORAGE_FLAG_MMAP_DISABLE |
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if ((storage->flags & MAIL_STORAGE_FLAG_NFS_FLUSH_INDEX) != 0)
564e117d86ce5b659f9b9570edddc566f9ebb5dfStephan Bosch if ((storage->flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0)
7c7117e542b6a44c1db7fc91c0180bdace6dbce7Stephan Bosch squat_trie_init(t_strconcat(path, "/"SQUAT_FILE_PREFIX, NULL),
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainenstatic void fts_backend_squat_deinit(struct fts_backend *_backend)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic int fts_backend_squat_get_last_uid(struct fts_backend *_backend,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return squat_trie_get_last_uid(backend->trie, last_uid_r);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_build_init(struct fts_backend *_backend, uint32_t *last_uid_r,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen if (squat_trie_build_init(backend->trie, last_uid_r, &build_ctx) < 0)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen ctx = i_new(struct squat_fts_backend_build_context, 1);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_build_more(struct fts_backend_build_context *_ctx,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch (struct squat_fts_backend_build_context *)_ctx;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch squat_type = headers ? SQUAT_INDEX_TYPE_HEADER :
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return squat_trie_build_more(ctx->build_ctx, uid, squat_type,
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschstatic int get_all_msg_uids(struct mailbox *box, ARRAY_TYPE(seq_range) *uids)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen search_ctx = mailbox_search_init(t, NULL, &search_arg, NULL);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen while ((ret = mailbox_search_next(search_ctx, mail)) > 0) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* *2 because even/odd is for body/header */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch seq_range_array_add_range(uids, mail->uid * 2,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainenfts_backend_squat_build_deinit(struct fts_backend_build_context *_ctx)
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch (struct squat_fts_backend_build_context *)_ctx;
3cda61e4ccaa1192528776d315f7ed5534315cb0Stephan Bosch if (get_all_msg_uids(ctx->ctx.backend->box, &uids) < 0)
3cda61e4ccaa1192528776d315f7ed5534315cb0Stephan Bosch ret = squat_trie_build_deinit(&ctx->build_ctx, NULL);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch seq_range_array_invert(&uids, 2, (uint32_t)-2);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch ret = squat_trie_build_deinit(&ctx->build_ctx, &uids);
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschfts_backend_squat_expunge(struct fts_backend *_backend ATTR_UNUSED,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_expunge_finish(struct fts_backend *_backend,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic int fts_backend_squat_lock(struct fts_backend *_backend)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic void fts_backend_squat_unlock(struct fts_backend *_backend ATTR_UNUSED)
9ec9b6f85c8fbe67bfac523a5e3d33d34f72dddcStephan Boschfts_backend_squat_lookup(struct fts_backend *_backend, const char *key,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_assert((flags & FTS_LOOKUP_FLAG_INVERT) == 0);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch return squat_trie_lookup(backend->trie, key, squat_type,