dsmiley commented on a change in pull request #1123: LUCENE-9093: Unified highlighter with word separator never gives context to the left URL: https://github.com/apache/lucene-solr/pull/1123#discussion_r361853606
########## File path: lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/LengthGoalBreakIterator.java ########## @@ -167,68 +146,70 @@ public int previous() { @Override public int following(int matchEndIndex) { - final int targetIdx = (matchEndIndex + 1) + (int)(lengthGoal * (1.f - fragmentAlignment)); + return following(matchEndIndex, (matchEndIndex + 1) + (int)(lengthGoal * (1.f - fragmentAlignment))); + } + + private int following(int matchEndIndex, int targetIdx) { if (targetIdx >= getText().getEndIndex()) { - return baseIter.last(); + if (currentCache == baseIter.last()) { + return DONE; + } + return currentCache = baseIter.last(); } final int afterIdx = baseIter.following(targetIdx - 1); if (afterIdx == DONE) { - return baseIter.current(); + currentCache = baseIter.last(); + return DONE; } if (afterIdx == targetIdx) { // right on the money - return afterIdx; + return currentCache = afterIdx; } if (isMinimumLength) { // thus never undershoot - return afterIdx; + return currentCache = afterIdx; } // note: it is a shame that we invoke preceding() *one more time*; BI's are sometimes expensive. // Find closest break to target final int beforeIdx = baseIter.preceding(targetIdx); if (targetIdx - beforeIdx < afterIdx - targetIdx && beforeIdx > matchEndIndex) { - return beforeIdx; + return currentCache = beforeIdx; } - return afterIdx; - } - - private int moveToBreak(int idx) { // precondition: idx is a known break Review comment: Yay; moveToBreak be gone ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org