[dovecot-cvs] dovecot/src/plugins/fts fts-api-private.h, 1.1, 1.2 fts-api.c, 1.2, 1.3 fts-api.h, 1.1, 1.2 fts-storage.c, 1.2, 1.3

cras at dovecot.org cras at dovecot.org
Mon Sep 18 01:27:18 EEST 2006


Update of /var/lib/cvs/dovecot/src/plugins/fts
In directory talvi:/tmp/cvs-serv10342

Modified Files:
	fts-api-private.h fts-api.c fts-api.h fts-storage.c 
Log Message:
API updates and some fixes



Index: fts-api-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-api-private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- fts-api-private.h	17 Sep 2006 16:28:12 -0000	1.1
+++ fts-api-private.h	17 Sep 2006 22:27:16 -0000	1.2
@@ -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);

Index: fts-api.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-api.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- fts-api.c	17 Sep 2006 16:34:08 -0000	1.2
+++ fts-api.c	17 Sep 2006 22:27:16 -0000	1.3
@@ -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);
 }

Index: fts-api.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-api.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- fts-api.h	17 Sep 2006 16:28:12 -0000	1.1
+++ fts-api.h	17 Sep 2006 22:27:16 -0000	1.2
@@ -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);
 

Index: fts-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-storage.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- fts-storage.c	17 Sep 2006 16:34:08 -0000	1.2
+++ fts-storage.c	17 Sep 2006 22:27:16 -0000	1.3
@@ -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);
-	i_free(fbox);
 
-	return fbox->super.close(box);
+	ret = fbox->super.close(box);
+	i_free(fbox);
+	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)



More information about the dovecot-cvs mailing list