mirror of https://github.com/apache/lucene.git
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:
parent
f4356a30fe
commit
286bb69c83
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue