LUCENE-5166: also fix and test this case where tf > 1 within the passage for a term

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1514367 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-08-15 16:52:15 +00:00
parent f4356a30fe
commit 286bb69c83
2 changed files with 34 additions and 7 deletions

View File

@ -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;
}

View File

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