Traktormaster 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_r361840892
########## File path: lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/LengthGoalBreakIteratorTest.java ########## @@ -39,65 +41,142 @@ // 0 1 // 01234567890123456789 static final String CONTENT = "Aa bb. Cc dd. Ee ff"; + static final String CONTENT2 = "Aa bb Cc dd X Ee ff Gg hh."; + + public void testFragmentAlignmentConstructor() throws IOException { + BreakIterator baseBI = new CustomSeparatorBreakIterator('.'); + // test fragmentAlignment validation + float[] valid_aligns = {0.f, 0.3333f, 0.5f, 0.99f, 1.f}; + for (float alignment : valid_aligns) { + LengthGoalBreakIterator.createClosestToLength(baseBI, 50, alignment); + } + float[] invalid_aligns = {-0.01f, -1.f, 1.5f, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}; + for (float alignment : invalid_aligns) { + expectThrows(IllegalArgumentException.class, () -> { + LengthGoalBreakIterator.createClosestToLength(baseBI, 50, alignment); + }); + } + // test backwards compatibility constructors + String backwardCompString = LengthGoalBreakIterator.createClosestToLength(baseBI, 50).toString(); + assertTrue(backwardCompString, backwardCompString.contains("fragAlign=0.0")); + backwardCompString = LengthGoalBreakIterator.createMinLength(baseBI, 50).toString(); + assertTrue(backwardCompString, backwardCompString.contains("fragAlign=0.0")); + } public void testTargetLen() throws IOException { // "goal" means target length goal to find closest break // at first word: Query query = query("aa"); - assertEquals("almost two sent", - "<b>Aa</b> bb.", highlightClosestToLen(CONTENT, query, 9)); Review comment: **EDIT**: NVM this, I've checked this and it was never a problem, but could be in the proposed version. I've not checked this but thinking about it makes me believe that previous to my changes this could have happened regardless, since the `following()` was called with `start` instead of `end - 1`. The reason it was not a problem could be that it would only happen at a ridiculously low `fragsize`. ---------------------------------------------------------------- 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