From 5e4df50bf0826484dc87ea9175fa42618123ca3e Mon Sep 17 00:00:00 2001 From: hung phan Date: Mon, 20 Jan 2025 17:57:50 +0700 Subject: [PATCH] fixup! JAMES-4100 Improve Search Snippet display --- .../james/mailbox/lucene/search/LuceneIndexableDocument.java | 4 ++-- .../james/mailbox/opensearch/json/IndexableMessage.java | 4 ++-- .../org/apache/james/mailbox/store/search/SearchUtil.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneIndexableDocument.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneIndexableDocument.java index 6d0222204f5..4f14d14c3f8 100644 --- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneIndexableDocument.java +++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneIndexableDocument.java @@ -195,8 +195,8 @@ public Document createMessageDocument(MailboxMessage message, MailboxSession ses doc.add(new TextField(BCC_FIELD, uppercase(EMailers.from(headerCollection.getBccAddressSet()).serialize()), Field.Store.YES)); // index body - Optional bodyText = mimePartExtracted.locateFirstTextBody().map(SearchUtil::removeGreaterThanCharacters); - Optional bodyHtml = mimePartExtracted.locateFirstHtmlBody().map(SearchUtil::removeGreaterThanCharacters); + Optional bodyText = mimePartExtracted.locateFirstTextBody().map(SearchUtil::removeGreaterThanCharactersAtBeginningOfLine); + Optional bodyHtml = mimePartExtracted.locateFirstHtmlBody(); bodyText.or(() -> bodyHtml) .ifPresent(bodyContent -> doc.add(new TextField(BODY_FIELD, bodyContent, Field.Store.YES))); diff --git a/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/json/IndexableMessage.java b/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/json/IndexableMessage.java index 20804d8688c..8bfaf646f88 100644 --- a/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/json/IndexableMessage.java +++ b/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/json/IndexableMessage.java @@ -135,8 +135,8 @@ private Mono instantiateIndexedMessage() throws IOException, M .asMimePart(textExtractor) .map(parsingResult -> { - Optional bodyText = parsingResult.locateFirstTextBody().map(SearchUtil::removeGreaterThanCharacters); - Optional bodyHtml = parsingResult.locateFirstHtmlBody().map(SearchUtil::removeGreaterThanCharacters); + Optional bodyText = parsingResult.locateFirstTextBody().map(SearchUtil::removeGreaterThanCharactersAtBeginningOfLine); + Optional bodyHtml = parsingResult.locateFirstHtmlBody(); boolean hasAttachment = MessageAttachmentMetadata.hasNonInlinedAttachment(message.getAttachments()); List attachments = setFlattenedAttachments(parsingResult, indexAttachments); diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java index 0574b4a69a4..0a90b132b65 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java @@ -473,7 +473,7 @@ public boolean test(MessageId input) { }; } - public static String removeGreaterThanCharacters(String text) { + public static String removeGreaterThanCharactersAtBeginningOfLine(String text) { StringBuilder result = new StringBuilder(); boolean isNewLine = false;