Mercurial > dovecot > core-2.2
changeset 4618:a1621235f405 HEAD
API updates and some fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 18 Sep 2006 01:27:16 +0300 |
parents | 3c05b1f71ce6 |
children | 3111cf26ecac |
files | src/plugins/fts/fts-api-private.h src/plugins/fts/fts-api.c src/plugins/fts/fts-api.h src/plugins/fts/fts-storage.c |
diffstat | 4 files changed, 45 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/fts/fts-api-private.h Mon Sep 18 00:08:06 2006 +0300 +++ b/src/plugins/fts/fts-api-private.h Mon Sep 18 01:27:16 2006 +0300 @@ -11,7 +11,7 @@ (*build_init)(struct fts_backend *backend, uint32_t *last_uid_r); int (*build_more)(struct fts_backend_build_context *ctx, uint32_t uid, - const void *data, size_t size); + const unsigned char *data, size_t size); int (*build_deinit)(struct fts_backend_build_context *ctx); int (*lookup)(struct fts_backend *backend, const char *key, @@ -22,11 +22,18 @@ struct fts_backend { const char *name; + /* If TRUE, lookup() and filter() are trusted to return only + actual matches. Otherwise the returned mails are opened and + searched. */ + bool definite_lookups; + struct fts_backend_vfuncs v; }; struct fts_backend_build_context { struct fts_backend *backend; + + unsigned int failed:1; }; void fts_backend_register(const struct fts_backend *backend);
--- a/src/plugins/fts/fts-api.c Mon Sep 18 00:08:06 2006 +0300 +++ b/src/plugins/fts/fts-api.c Mon Sep 18 01:27:16 2006 +0300 @@ -59,7 +59,7 @@ } int fts_backend_build_more(struct fts_backend_build_context *ctx, uint32_t uid, - const void *data, size_t size) + const unsigned char *data, size_t size) { return ctx->backend->v.build_more(ctx, uid, data, size); }
--- a/src/plugins/fts/fts-api.h Mon Sep 18 00:08:06 2006 +0300 +++ b/src/plugins/fts/fts-api.h Mon Sep 18 01:27:16 2006 +0300 @@ -7,14 +7,24 @@ fts_backend_init(const char *backend_name, const char *path); void fts_backend_deinit(struct fts_backend *backend); +/* Initialize adding new data to the index. last_uid_r is set to the last UID + that exists in the index. */ struct fts_backend_build_context * fts_backend_build_init(struct fts_backend *backend, uint32_t *last_uid_r); +/* Add more contents to the index. The data must contain only full valid + UTF-8 characters, but it doesn't need to be NUL-terminated. size contains + the data size in bytes, not characters. */ int fts_backend_build_more(struct fts_backend_build_context *ctx, uint32_t uid, - const void *data, size_t size); + const unsigned char *data, size_t size); +/* Finish adding new data to the index. */ int fts_backend_build_deinit(struct fts_backend_build_context *ctx); +/* Lookup key from the index and return the found UIDs in result. */ int fts_backend_lookup(struct fts_backend *backend, const char *key, ARRAY_TYPE(seq_range) *result); +/* Drop UIDs from the result list for which the key doesn't exist. The idea + is that with multiple search keywords you first lookup one and then filter + the rest. */ int fts_backend_filter(struct fts_backend *backend, const char *key, ARRAY_TYPE(seq_range) *result);
--- a/src/plugins/fts/fts-storage.c Mon Sep 18 00:08:06 2006 +0300 +++ b/src/plugins/fts/fts-storage.c Mon Sep 18 01:27:16 2006 +0300 @@ -35,11 +35,13 @@ static int fts_mailbox_close(struct mailbox *box) { struct fts_mailbox *fbox = FTS_CONTEXT(box); + int ret; fts_backend_deinit(fbox->backend); + + ret = fbox->super.close(box); i_free(fbox); - - return fbox->super.close(box); + return ret; } static int uid_range_to_seq(struct mailbox *box, @@ -149,7 +151,7 @@ break; if (ret == 0) skip_part = raw_block.part; - } else { + } else if (block.size != 0) { if (fts_backend_build_more(ctx->build, mail->uid, block.data, block.size) < 0) { @@ -244,10 +246,18 @@ array_free(&uid_result); } + if (fbox->backend->definite_lookups) { + args->match_always = TRUE; + args->result = 1; + } args = args->next; while (args != NULL) { if (args->type == SEARCH_BODY || args->type == SEARCH_TEXT) { + if (fbox->backend->definite_lookups) { + args->match_always = TRUE; + args->result = 1; + } if (fts_backend_filter(fbox->backend, args->value.str, &uid_result) < 0) { @@ -274,8 +284,13 @@ struct fts_search_context *fctx = FTS_CONTEXT(ctx); struct seq_range *range; unsigned int count; + uint32_t wanted_seq; + int ret; - if (array_is_created(&fctx->result)) { + if (!array_is_created(&fctx->result)) + return fbox->super.search_next_update_seq(ctx); + + do { range = array_get_modifiable(&fctx->result, &count); while (fctx->result_pos < count && ctx->seq > range[fctx->result_pos].seq2) @@ -290,8 +305,12 @@ ctx->seq = range[fctx->result_pos].seq1 - 1; range[fctx->result_pos].seq1++; } - } - return fbox->super.search_next_update_seq(ctx); + + wanted_seq = ctx->seq + 1; + ret = fbox->super.search_next_update_seq(ctx); + } while (ret > 0 && wanted_seq != ctx->seq); + + return ret; } static int fts_mailbox_search_deinit(struct mail_search_context *ctx)