LUCENE-1321: Highlight fragment does not extend to maxDocCharsToAnalyze

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@673220 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2008-07-01 21:44:33 +00:00
parent ebf4625870
commit 943bf37e66
2 changed files with 22 additions and 1 deletions

View File

@ -285,7 +285,7 @@ public class Highlighter
(lastEndOffset < text.length())
&&
// and that text is not too large...
(text.length()< maxDocCharsToAnalyze)
(text.length()<= maxDocCharsToAnalyze)
)
{
//append it to the last fragment

View File

@ -876,6 +876,27 @@ public class HighlighterTest extends TestCase implements Formatter {
helper.start();
}
public void testMaxSizeEndHighlight() throws Exception {
TestHighlightRunner helper = new TestHighlightRunner() {
public void run() throws Exception {
String stopWords[] = { "in", "it" };
TermQuery query = new TermQuery(new Term("text", "searchterm"));
String text = "this is a text with searchterm in it";
SimpleHTMLFormatter fm = new SimpleHTMLFormatter();
Highlighter hg = getHighlighter(query, "text", new StandardAnalyzer(
stopWords).tokenStream("text", new StringReader(text)), fm);
hg.setTextFragmenter(new NullFragmenter());
hg.setMaxDocCharsToAnalyze(36);
String match = hg.getBestFragment(new StandardAnalyzer(stopWords), "text", text);
assertTrue(
"Matched text should contain remainder of text after highlighted query ",
match.endsWith("in it"));
}
};
helper.start();
}
public void testUnRewrittenQuery() throws Exception {
TestHighlightRunner helper = new TestHighlightRunner() {