fts-backend-squat.c revision 4ae81f8f7aad06aad2f570535cad6e40aaec2b28
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "lib.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "array.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "mail-storage-private.h"
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch#include "mail-search.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "squat-trie.h"
833bed942977673526c72e79bccc09314fc57104Phil Carmody#include "fts-squat-plugin.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch#include <stdlib.h>
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#define SQUAT_FILE_PREFIX "dovecot.index.search"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstruct squat_fts_backend {
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct fts_backend backend;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct squat_trie *trie;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch};
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstruct squat_fts_backend_build_context {
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct fts_backend_build_context ctx;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct squat_trie_build_context *build_ctx;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch};
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic void
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_set(struct squat_fts_backend *backend, const char *str)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch{
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch const char *const *tmp;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch int len;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch for (tmp = t_strsplit_spaces(str, " "); *tmp != NULL; tmp++) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if (strncmp(*tmp, "partial=", 8) == 0) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch len = atoi(*tmp + 8);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if (len <= 0) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_fatal("fts_squat: Invalid partial len: %s",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch *tmp + 8);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch squat_trie_set_partial_len(backend->trie, len);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch } else if (strncmp(*tmp, "full=", 5) == 0) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch len = atoi(*tmp + 5);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if (len <= 0) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_fatal("fts_squat: Invalid full len: %s",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch *tmp + 5);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch squat_trie_set_full_len(backend->trie, len);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch } else {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_fatal("fts_squat: Invalid setting: %s", *tmp);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic struct fts_backend *fts_backend_squat_init(struct mailbox *box)
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch{
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct squat_fts_backend *backend;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct mail_storage *storage;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct mailbox_status status;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch const char *path, *env;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch enum squat_index_flags flags = 0;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch storage = mailbox_get_storage(box);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch path = mail_storage_get_mailbox_index_dir(storage,
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch mailbox_get_name(box));
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch if (*path == '\0') {
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch /* in-memory indexes */
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch return NULL;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch mailbox_get_status(box, STATUS_UIDVALIDITY, &status);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if ((storage->flags & (MAIL_STORAGE_FLAG_MMAP_DISABLE |
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch MAIL_STORAGE_FLAG_MMAP_NO_WRITE)) != 0)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch flags |= SQUAT_INDEX_FLAG_MMAP_DISABLE;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if ((storage->flags & MAIL_STORAGE_FLAG_NFS_FLUSH_INDEX) != 0)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch flags |= SQUAT_INDEX_FLAG_NFS_FLUSH;
564e117d86ce5b659f9b9570edddc566f9ebb5dfStephan Bosch if ((storage->flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch flags |= SQUAT_INDEX_FLAG_DOTLOCK_USE_EXCL;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch backend = i_new(struct squat_fts_backend, 1);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch backend->backend = fts_backend_squat;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch backend->trie =
7c7117e542b6a44c1db7fc91c0180bdace6dbce7Stephan Bosch squat_trie_init(t_strconcat(path, "/"SQUAT_FILE_PREFIX, NULL),
7c7117e542b6a44c1db7fc91c0180bdace6dbce7Stephan Bosch status.uidvalidity, storage->lock_method,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch flags);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch env = getenv("FTS_SQUAT");
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen if (env != NULL)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen fts_backend_squat_set(backend, env);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen return &backend->backend;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen}
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainenstatic void fts_backend_squat_deinit(struct fts_backend *_backend)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen{
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen struct squat_fts_backend *backend =
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen (struct squat_fts_backend *)_backend;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch squat_trie_deinit(&backend->trie);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_free(backend);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic int fts_backend_squat_get_last_uid(struct fts_backend *_backend,
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch uint32_t *last_uid_r)
dc05b1fb4b7a2b4d91248078311458cb4cbad9a1Stephan Bosch{
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct squat_fts_backend *backend =
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch (struct squat_fts_backend *)_backend;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return squat_trie_get_last_uid(backend->trie, last_uid_r);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic int
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_build_init(struct fts_backend *_backend, uint32_t *last_uid_r,
201c3b9375760bafbc180629b4c6ad71ed554aecStephan Bosch struct fts_backend_build_context **ctx_r)
201c3b9375760bafbc180629b4c6ad71ed554aecStephan Bosch{
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct squat_fts_backend *backend =
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch (struct squat_fts_backend *)_backend;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct squat_fts_backend_build_context *ctx;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct squat_trie_build_context *build_ctx;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen if (squat_trie_build_init(backend->trie, last_uid_r, &build_ctx) < 0)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen return -1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen ctx = i_new(struct squat_fts_backend_build_context, 1);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen ctx->ctx.backend = _backend;
a5886aec87fbfd767a110e6168ce96411acfe798Stephan Bosch ctx->build_ctx = build_ctx;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch *ctx_r = &ctx->ctx;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return 0;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic int
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_build_more(struct fts_backend_build_context *_ctx,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch uint32_t uid, const unsigned char *data,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch size_t size, bool headers)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch{
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct squat_fts_backend_build_context *ctx =
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch (struct squat_fts_backend_build_context *)_ctx;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch enum squat_index_type squat_type;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch squat_type = headers ? SQUAT_INDEX_TYPE_HEADER :
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch SQUAT_INDEX_TYPE_BODY;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return squat_trie_build_more(ctx->build_ctx, uid, squat_type,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch data, size);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschstatic int get_all_msg_uids(struct mailbox *box, ARRAY_TYPE(seq_range) *uids)
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch{
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct mailbox_transaction_context *t;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct mail_search_context *search_ctx;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct mail_search_arg search_arg;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct mail *mail;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch int ret = 0;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen t = mailbox_transaction_begin(box, 0);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen memset(&search_arg, 0, sizeof(search_arg));
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen search_arg.type = SEARCH_ALL;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen mail = mail_alloc(t, 0, NULL);
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,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch mail->uid * 2 + 1);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if (mailbox_search_deinit(&search_ctx) < 0)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch ret = -1;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch mail_free(&mail);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch (void)mailbox_transaction_commit(&t);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return ret;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
e1a4ea6ad3e799ef8df7395e765c0ae9218e6c5dStephan Boschstatic int
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainenfts_backend_squat_build_deinit(struct fts_backend_build_context *_ctx)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch{
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct squat_fts_backend_build_context *ctx =
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch (struct squat_fts_backend_build_context *)_ctx;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch ARRAY_TYPE(seq_range) uids;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch int ret;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch i_array_init(&uids, 1024);
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 else {
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch seq_range_array_invert(&uids, 2, (uint32_t)-2);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch ret = squat_trie_build_deinit(&ctx->build_ctx, &uids);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch }
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch array_free(&uids);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_free(ctx);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return ret;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschstatic void
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschfts_backend_squat_expunge(struct fts_backend *_backend ATTR_UNUSED,
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch struct mail *mail ATTR_UNUSED)
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch{
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch}
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschstatic void
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschfts_backend_squat_expunge_finish(struct fts_backend *_backend,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct mailbox *box, bool committed)
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch{
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch /* FIXME */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic int fts_backend_squat_lock(struct fts_backend *_backend)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch{
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch struct squat_fts_backend *backend =
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch (struct squat_fts_backend *)_backend;
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch squat_trie_refresh(backend->trie);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch return 1;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch}
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic void fts_backend_squat_unlock(struct fts_backend *_backend ATTR_UNUSED)
faa8995f1d300e7a8917407a52bbd1b98e10bf25Timo Sirainen{
ee2633056e67353157bfbce4d9e0d1c3ceaa627aStephan Bosch}
ee2633056e67353157bfbce4d9e0d1c3ceaa627aStephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic int
9ec9b6f85c8fbe67bfac523a5e3d33d34f72dddcStephan Boschfts_backend_squat_lookup(struct fts_backend *_backend, const char *key,
9ec9b6f85c8fbe67bfac523a5e3d33d34f72dddcStephan Bosch enum fts_lookup_flags flags,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch ARRAY_TYPE(seq_range) *definite_uids,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch ARRAY_TYPE(seq_range) *maybe_uids)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch{
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch struct squat_fts_backend *backend =
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch (struct squat_fts_backend *)_backend;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch enum squat_index_type squat_type = 0;
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_assert((flags & FTS_LOOKUP_FLAG_INVERT) == 0);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch if ((flags & FTS_LOOKUP_FLAG_HEADER) != 0)
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch squat_type |= SQUAT_INDEX_TYPE_HEADER;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch if ((flags & FTS_LOOKUP_FLAG_BODY) != 0)
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch squat_type |= SQUAT_INDEX_TYPE_BODY;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch i_assert(squat_type != 0);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch return squat_trie_lookup(backend->trie, key, squat_type,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch definite_uids, maybe_uids);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch}
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschstruct fts_backend fts_backend_squat = {
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch MEMBER(name) "squat",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch MEMBER(flags) FTS_BACKEND_FLAG_SUBSTRING_LOOKUPS,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch fts_backend_squat_init,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_deinit,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_get_last_uid,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_build_init,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch fts_backend_squat_build_more,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_build_deinit,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_expunge,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch fts_backend_squat_expunge_finish,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_lock,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_unlock,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch fts_backend_squat_lookup,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch NULL
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch }
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch};
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch