mirror of https://github.com/apache/lucene.git
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:
parent
ebf4625870
commit
943bf37e66
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue