changeset 11616:776e2d96f6bb HEAD

fts-solr: Fixed handling indexing for multiple body parts.
author Timo Sirainen <tss@iki.fi>
date Tue, 22 Jun 2010 22:41:55 +0100
parents 7ad62742116d
children 29178cec0506
files src/plugins/fts-solr/fts-backend-solr.c
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/fts-solr/fts-backend-solr.c	Tue Jun 22 22:27:10 2010 +0100
+++ b/src/plugins/fts-solr/fts-backend-solr.c	Tue Jun 22 22:41:55 2010 +0100
@@ -29,6 +29,7 @@
 	uint32_t prev_uid, uid_validity;
 	string_t *cmd;
 	bool headers;
+	bool field_open;
 };
 
 struct solr_virtual_uid_map_context {
@@ -569,7 +570,11 @@
 		ctx->post = solr_connection_post_begin(solr_conn);
 		str_append(ctx->cmd, "<add>");
 	} else {
-		str_append(ctx->cmd, "</field></doc>");
+		if (ctx->field_open) {
+			str_append(ctx->cmd, "</field>");
+			ctx->field_open = FALSE;
+		}
+		str_append(ctx->cmd, "</doc>");
 	}
 	ctx->prev_uid = uid;
 	ctx->headers = FALSE;
@@ -591,9 +596,15 @@
 		fts_backend_solr_uid_changed(ctx, uid);
 	else {
 		i_assert(!ctx->headers);
-		str_append(ctx->cmd, "</field>");
+
+		if (ctx->field_open) {
+			str_append(ctx->cmd, "</field>");
+			ctx->field_open = FALSE;
+		}
 	}
 
+	i_assert(!ctx->field_open);
+	ctx->field_open = TRUE;
 	ctx->headers = TRUE;
 	str_append(ctx->cmd, "<field name=\"hdr\">");
 }
@@ -616,6 +627,8 @@
 		i_assert(!ctx->headers);
 	}
 
+	i_assert(!ctx->field_open);
+	ctx->field_open = TRUE;
 	ctx->headers = FALSE;
 	str_append(ctx->cmd, "<field name=\"body\">");
 	return TRUE;
@@ -645,7 +658,11 @@
 	if (ctx->post == NULL)
 		return 0;
 
-	str_append(ctx->cmd, "</field></doc>");
+	if (ctx->field_open) {
+		str_append(ctx->cmd, "</field>");
+		ctx->field_open = FALSE;
+	}
+	str_append(ctx->cmd, "</doc>");
 
 	/* Update the mailbox's last_uid field, replacing the existing
 	   document. Note that since there is no locking, it's possible that