Index: contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java =================================================================== --- contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (revision 672706) +++ contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (working copy) @@ -1224,7 +1224,28 @@ 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 testBigramAnalyzer() throws IOException, ParseException { Index: contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java =================================================================== --- contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java (revision 672706) +++ contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java (working copy) @@ -285,7 +285,7 @@ (lastEndOffset < text.length()) && // and that text is not too large... - (text.length()< maxDocCharsToAnalyze) + (text.length()<= maxDocCharsToAnalyze) ) { //append it to the last fragment