dweiss commented on a change in pull request #334:
URL: https://github.com/apache/lucene/pull/334#discussion_r719145316



##########
File path: 
lucene/highlighter/src/java/org/apache/lucene/search/matchhighlight/PassageSelector.java
##########
@@ -127,8 +127,8 @@ protected boolean lessThan(Passage a, Passage b) {
         if (m.from >= range.from && m.to <= rangeTo && m.length() <= 
maxPassageWindow) {
 
           // Adjust the window range to center the highlight marker.
-          int from = (m.from + m.to - maxPassageWindow) / 2;
-          int to = (m.from + m.to + maxPassageWindow) / 2;
+          int from = Math.toIntExact(((long) m.from + m.to - maxPassageWindow) 
/ 2);

Review comment:
       Prevents overflow on very large maxPassageWindow.

##########
File path: 
lucene/highlighter/src/java/org/apache/lucene/search/matchhighlight/PassageSelector.java
##########
@@ -234,24 +234,30 @@ protected boolean lessThan(Passage a, Passage b) {
     ArrayList<OffsetRange> processedMarkers = new ArrayList<>(markers.size());
     for (OffsetRange marker : markers) {
       for (OffsetRange permitted : permittedPassageRanges) {
-        boolean needsNew = false;
+        boolean newSlice = false;
+
         int from = marker.from;
         if (from < permitted.from) {
           from = permitted.from;
-          needsNew = true;
+          newSlice = true;
         }
 
         int to = marker.to;
         if (to > permitted.to) {
           to = permitted.to;
-          needsNew = true;
+          newSlice = true;
         }
 
-        if (from >= to || (to - from) > maxPassageWindow) {
+        if (from >= to) {

Review comment:
       This is the actual change - if the highlight exceeds maxPassageWindow, 
it will be sliced to fit.




-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to