Mercurial > dovecot > core-2.2
changeset 13435:283e08771d92
fts-solr: Fixed indexing messages with multiple MIME body parts.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 Sep 2011 16:37:56 +0300 |
parents | 1aa51cd11614 |
children | 960907bfc29e |
files | src/plugins/fts-solr/fts-backend-solr-old.c src/plugins/fts-solr/fts-backend-solr.c |
diffstat | 2 files changed, 29 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/fts-solr/fts-backend-solr-old.c Thu Sep 08 12:39:13 2011 +0300 +++ b/src/plugins/fts-solr/fts-backend-solr-old.c Thu Sep 08 16:37:56 2011 +0300 @@ -36,6 +36,7 @@ string_t *cmd, *hdr; bool headers_open; + bool body_open; bool documents_added; }; @@ -513,6 +514,10 @@ str_append(ctx->cmd, "<add>"); } else { ctx->headers_open = FALSE; + if (ctx->body_open) { + ctx->body_open = FALSE; + str_append(ctx->cmd, "</field>"); + } str_append(ctx->cmd, "<field name=\"hdr\">"); str_append_str(ctx->cmd, ctx->hdr); str_append(ctx->cmd, "</field>"); @@ -547,7 +552,10 @@ break; case FTS_BACKEND_BUILD_KEY_BODY_PART: ctx->headers_open = FALSE; - str_append(ctx->cmd, "<field name=\"body\">"); + if (!ctx->body_open) { + ctx->body_open = TRUE; + str_append(ctx->cmd, "<field name=\"body\">"); + } break; case FTS_BACKEND_BUILD_KEY_BODY_PART_BINARY: i_unreached(); @@ -561,10 +569,12 @@ struct solr_fts_backend_update_context *ctx = (struct solr_fts_backend_update_context *)_ctx; - if (!ctx->headers_open) - str_append(ctx->cmd, "</field>"); - else + if (ctx->headers_open) str_append_c(ctx->hdr, '\n'); + else { + i_assert(ctx->body_open); + str_append_c(ctx->cmd, '\n'); + } } static int
--- a/src/plugins/fts-solr/fts-backend-solr.c Thu Sep 08 12:39:13 2011 +0300 +++ b/src/plugins/fts-solr/fts-backend-solr.c Thu Sep 08 16:37:56 2011 +0300 @@ -36,6 +36,7 @@ unsigned int last_indexed_uid_set:1; unsigned int headers_open:1; + unsigned int body_open:1; unsigned int cur_header_index:1; unsigned int documents_added:1; unsigned int expunges:1; @@ -260,6 +261,10 @@ fts_backend_solr_doc_close(struct solr_fts_backend_update_context *ctx) { ctx->headers_open = FALSE; + if (ctx->body_open) { + ctx->body_open = FALSE; + str_append(ctx->cmd, "</field>"); + } if (str_len(ctx->hdr) > 0) { str_append(ctx->cmd, "<field name=\"hdr\">"); str_append_str(ctx->cmd, ctx->hdr); @@ -416,7 +421,10 @@ break; case FTS_BACKEND_BUILD_KEY_BODY_PART: ctx->headers_open = FALSE; - str_append(ctx->cmd, "<field name=\"body\">"); + if (!ctx->body_open) { + ctx->body_open = TRUE; + str_append(ctx->cmd, "<field name=\"body\">"); + } break; case FTS_BACKEND_BUILD_KEY_BODY_PART_BINARY: i_unreached(); @@ -430,12 +438,15 @@ struct solr_fts_backend_update_context *ctx = (struct solr_fts_backend_update_context *)_ctx; - if (!ctx->headers_open) - str_append(ctx->cmd, "</field>"); - else { + if (ctx->headers_open) { /* this is called individually for each header line. headers are finished only when key changes to body */ str_append_c(ctx->hdr, '\n'); + } else { + i_assert(ctx->body_open); + /* messages can have multiple MIME bodies. + add them all as one. */ + str_append_c(ctx->cmd, '\n'); } if (ctx->cur_header_index) {