LUCENE-4486: Add support for ConstantScoreQuery in Highlighter.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1399205 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2012-10-17 12:40:46 +00:00
parent 398d987b19
commit 2becc99249
3 changed files with 34 additions and 1 deletions

View File

@ -56,6 +56,9 @@ Bug Fixes
* LUCENE-4468: Fix rareish integer overflows in Block and Lucene40 postings
formats (Robert Muir)
* LUCENE-4486: Add support for ConstantScoreQuery in Highlighter.
(Simon Willnauer)
* LUCENE-4485: When CheckIndex terms, terms/docs pairs and tokens,
these counts now all exclude deleted documents. (Mike McCandless)

View File

@ -141,6 +141,11 @@ public class WeightedSpanTermExtractor {
extractWeightedSpanTerms(terms, (SpanQuery) query);
} else if (query instanceof FilteredQuery) {
extract(((FilteredQuery) query).getQuery(), terms);
} else if (query instanceof ConstantScoreQuery) {
final Query q = ((ConstantScoreQuery) query).getQuery();
if (q != null) {
extract(q, terms);
}
} else if (query instanceof DisjunctionMaxQuery) {
for (Iterator<Query> iterator = ((DisjunctionMaxQuery) query).iterator(); iterator.hasNext();) {
extract(iterator.next(), terms);

View File

@ -603,7 +603,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
// Not sure we can assert anything here - just running to check we dont
// throw any exceptions
}
public void testSpanHighlighting() throws Exception {
Query query1 = new SpanNearQuery(new SpanQuery[] {
new SpanTermQuery(new Term(FIELD_NAME, "wordx")),
@ -663,6 +663,31 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
helper.start();
}
public void testGetBestFragmentsConstantScore() throws Exception {
TestHighlightRunner helper = new TestHighlightRunner() {
@Override
public void run() throws Exception {
numHighlights = 0;
if (random().nextBoolean()) {
BooleanQuery bq = new BooleanQuery();
bq.add(new ConstantScoreQuery(new QueryWrapperFilter(new TermQuery(
new Term(FIELD_NAME, "kennedy")))), Occur.MUST);
bq.add(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME, "kennedy"))), Occur.MUST);
doSearching(bq);
} else {
doSearching(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME,
"kennedy"))));
}
doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
numHighlights == 4);
}
};
helper.start();
}
public void testGetFuzzyFragments() throws Exception {
TestHighlightRunner helper = new TestHighlightRunner() {