From 943bf37e66b3e0a63ac4d5bf68404715bf34bb4f Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Tue, 1 Jul 2008 21:44:33 +0000 Subject: [PATCH] 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 --- .../lucene/search/highlight/Highlighter.java | 2 +- .../search/highlight/HighlighterTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java index 8d13af2b57a..7d615d4b9b8 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java @@ -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 diff --git a/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java index e8d0323381f..cc0d402b5a3 100644 --- a/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java +++ b/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java @@ -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() {