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 5be03999834..36355e36298 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 @@ -70,6 +70,7 @@ import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner; +import org.apache.lucene.search.regex.RegexQuery; import org.apache.lucene.search.regex.SpanRegexQuery; import org.apache.lucene.search.spans.SpanNearQuery; import org.apache.lucene.search.spans.SpanNotQuery; @@ -333,6 +334,30 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte numHighlights == 5); } + public void testRegexQuery() throws Exception { + query = new RegexQuery(new Term(FIELD_NAME, "ken.*")); + searcher = new IndexSearcher(ramDir, true); + hits = searcher.search(query, 100); + int maxNumFragmentsRequired = 2; + + QueryScorer scorer = new QueryScorer(query, FIELD_NAME); + Highlighter highlighter = new Highlighter(this, scorer); + + for (int i = 0; i < hits.totalHits; i++) { + String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME); + TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(text)); + + highlighter.setTextFragmenter(new SimpleFragmenter(40)); + + String result = highlighter.getBestFragments(tokenStream, text, maxNumFragmentsRequired, + "..."); + System.out.println("\t" + result); + } + + assertTrue("Failed to find correct number of highlights " + numHighlights + " found", + numHighlights == 5); + } + public void testNumericRangeQuery() throws Exception { // doesn't currently highlight, but make sure it doesn't cause exception either query = NumericRangeQuery.newIntRange(NUMERIC_FIELD_NAME, 2, 6, true, true);