Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAMES-4100 Improve Search Snippet display #2583

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hungphan227
Copy link
Contributor

No description provided.

StringBuilder result = new StringBuilder();
boolean previousIsTarget = false;

for (char c : text.toCharArray()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have doubts about char iteration method.

Maybe we could bench with JMH this version and the REGEXP one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested both ways with JMH in an isolated test (run method shortenGreaterThanCharacters in a loop with 10000 iterations). Both have the same results (around 3ms)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use regex?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a fan of neither of both approaches to be fairly honnest..

Copy link
Contributor

@Arsnael Arsnael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read it, nothing to add

@quantranhong1999
Copy link
Contributor

@@ -90,8 +90,28 @@ private SearchSnippet buildSearchSnippet(Hit<ObjectNode> searchResult) {
Optional<String> highlightedTextBody = Optional.ofNullable(highlightHit.get(JsonMessageConstants.TEXT_BODY))
.or(() -> Optional.ofNullable(highlightHit.get(JsonMessageConstants.HTML_BODY)))
.or(() -> Optional.ofNullable(highlightHit.get(ATTACHMENT_TEXT_CONTENT_FIELD)))
.map(List::getFirst);
.map(List::getFirst)
.map(this::shortenGreaterThanCharacters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename it to prettyHighlightedText or foldHighlightedText is better?

@Arsnael
Copy link
Contributor

Arsnael commented Jan 8, 2025

@chibenwa
Copy link
Contributor

chibenwa commented Jan 8, 2025

Have you tried

StringUtils.remove(s, '>);

Or

CharMatcher.is('>').removeFrom(s)

?

@hungphan227
Copy link
Contributor Author

Have you tried

StringUtils.remove(s, '>);

Or

CharMatcher.is('>').removeFrom(s)

?

Don't you want to keep at least one character after removing?

@chibenwa
Copy link
Contributor

chibenwa commented Jan 8, 2025

I do not know: how would it look like in the end user display?

@hungphan227
Copy link
Contributor Author

I do not know: how would it look like in the end user display?

Example:
Input: >>>>>>>>>> append contentA to >>> inbox >>>>>>
Result: > append contentA to > inbox >

(contentA is the highlighted part)

@chibenwa
Copy link
Contributor

chibenwa commented Jan 8, 2025

I wonder if append contentA to INBOX wouldn't be better...

@hungphan227
Copy link
Contributor Author

hungphan227 commented Jan 8, 2025

I wonder if append contentA to INBOX wouldn't be better...

The solution for this is not just StringUtils.remove(s, '>);. We should not remove > from <mark> tag of search snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants