| ### Eclipse Workspace Patch 1.0 |
| #P trunk |
| Index: lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java |
| =================================================================== |
| --- lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java (Revision 1514237) |
| +++ lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java (Arbeitskopie) |
| @@ -563,7 +563,7 @@ |
| start = dp.startOffset(); |
| end = dp.endOffset(); |
| } |
| - if (start >= current.endOffset) { |
| + if (start >= current.endOffset || end > contentLength) { |
| pq.offer(off); |
| break; |
| } |
| Index: lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java |
| =================================================================== |
| --- lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java (Revision 1514237) |
| +++ lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java (Arbeitskopie) |
| @@ -86,12 +86,42 @@ |
| 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 @@ |
| 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. |