Skip to content

Commit

Permalink
Fix issue with returning incomplete fragment for plain highlighter. (#…
Browse files Browse the repository at this point in the history
…110707)

* Fix issue with noMatchSize for plain highlighter

* Update docs/changelog/110707.yaml
  • Loading branch information
ioanatia authored Jul 11, 2024
1 parent 2d6efb7 commit 0f6c01a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/110707.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 110707
summary: Fix issue with returning incomplete fragment for plain highlighter
area: Highlighting
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,15 @@ public void testHighlightNoMatchSize() throws IOException {

field.highlighterType("unified");
assertNotHighlighted(prepareSearch("test").highlighter(new HighlightBuilder().field(field)), 0, "text");

// Check when the requested fragment size equals the size of the string
var anotherText = "I am unusual and don't end with your regular )token)";
indexDoc("test", "1", "text", anotherText);
refresh();
for (String type : new String[] { "plain", "unified", "fvh" }) {
field.highlighterType(type).noMatchSize(anotherText.length()).numOfFragments(0);
assertHighlight(prepareSearch("test").highlighter(new HighlightBuilder().field(field)), 0, "text", 0, 1, equalTo(anotherText));
}
}

public void testHighlightNoMatchSizeWithMultivaluedFields() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ private static int findGoodEndForNoHighlightExcerpt(int noMatchSize, Analyzer an
// Can't split on term boundaries without offsets
return -1;
}
if (contents.length() <= noMatchSize) {
return contents.length();
}
int end = -1;
tokenStream.reset();
while (tokenStream.incrementToken()) {
Expand Down

0 comments on commit 0f6c01a

Please sign in to comment.