Apache Lucene open-source search software
LUCENE-5166: also fix and test this case where tf > 1 within the passage for a term
Robert Muir286bb69c8358
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java b/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.javaindex 3d7b95d2aaf..355d5b25876 100644--- a/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java+++ b/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java@@ -563,7 +563,7 @@ public class PostingsHighlighter {start = dp.startOffset();end = dp.endOffset();}- if (start >= current.endOffset) {+ if (start >= current.endOffset || end > contentLength) {pq.offer(off);break;}diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java b/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.javaindex 10e2c5fa2c5..573cd5f8664 100644--- a/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java+++ b/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java@@ -86,12 +86,42 @@ public class TestPostingsHighlighter extends LuceneTestCase {ir.close();dir.close();}++ public void testFormatWithMatchExceedingContentLength2() throws Exception {++ String bodyText = "123 TEST 01234 TEST";++ String[] snippets = formatWithMatchExceedingContentLength(bodyText);++ assertEquals(1, snippets.length);+ assertEquals("123 <b>TEST</b> 01234 TE", snippets[0]);+ }++ public void testFormatWithMatchExceedingContentLength3() throws Exception {++ String bodyText = "123 5678 01234 TEST TEST";++ String[] snippets = formatWithMatchExceedingContentLength(bodyText);++ assertEquals(1, snippets.length);+ assertEquals("123 5678 01234 TE", snippets[0]);+ }public void testFormatWithMatchExceedingContentLength() throws Exception {-- int maxLength = 17;+String bodyText = "123 5678 01234 TEST";+ String[] snippets = formatWithMatchExceedingContentLength(bodyText);++ assertEquals(1, snippets.length);+ // LUCENE-5166: no snippet+ assertEquals("123 5678 01234 TE", snippets[0]);+ }++ private String[] formatWithMatchExceedingContentLength(String bodyText) throws IOException {++ int maxLength = 17;+final Analyzer analyzer = new MockAnalyzer(random());Directory dir = newDirectory();@@ -122,12 +152,9 @@ public class TestPostingsHighlighter extends LuceneTestCase {String snippets[] = highlighter.highlight("body", query, searcher, topDocs);- assertEquals(1, snippets.length);- // LUCENE-5166: no snippet- assertEquals("123 5678 01234 TE", snippets[0]);-ir.close();dir.close();+ return snippets;}// simple test highlighting last word.