LUCENE-6262: Don't wrap the inner weight in ConstantScoreQuery when scores are not required.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1661367 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrien Grand 2015-02-21 14:26:08 +00:00
parent 3dc3e57847
commit 487e9849e0
3 changed files with 13 additions and 5 deletions

View File

@ -98,6 +98,9 @@ Optimizations
filter out non-index files with some custom usage, you may want to look at
the IndexFileNames class. (Robert Muir)
* LUCENE-6262: ConstantScoreQuery does not wrap the inner weight anymore when
scores are not required. (Adrien Grand)
API Changes
* LUCENE-6204, LUCENE-6208: Simplify CompoundFormat: remove files()

View File

@ -78,9 +78,9 @@ public class ConstantScoreQuery extends Query {
private float queryNorm;
private float queryWeight;
public ConstantWeight(IndexSearcher searcher) throws IOException {
public ConstantWeight(Weight innerWeight) throws IOException {
super(ConstantScoreQuery.this);
this.innerWeight = query.createWeight(searcher, false);
this.innerWeight = innerWeight;
}
@Override
@ -277,7 +277,12 @@ public class ConstantScoreQuery extends Query {
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new ConstantScoreQuery.ConstantWeight(searcher);
final Weight innerWeight = query.createWeight(searcher, false);
if (needsScores) {
return new ConstantScoreQuery.ConstantWeight(innerWeight);
} else {
return innerWeight;
}
}
@Override

View File

@ -115,8 +115,8 @@ public class TestConstantScoreQuery extends LuceneTestCase {
final Query csqbq = new ConstantScoreQuery(bq);
csqbq.setBoost(17.0f);
checkHits(searcher, csq1, csq1.getBoost(), ConstantScoreQuery.ConstantScoreScorer.class.getName(), null);
checkHits(searcher, csq2, csq2.getBoost(), ConstantScoreQuery.ConstantScoreScorer.class.getName(), ConstantScoreQuery.ConstantScoreScorer.class.getName());
checkHits(searcher, csq1, csq1.getBoost(), ConstantScoreQuery.ConstantScoreScorer.class.getName(), TermScorer.class.getName());
checkHits(searcher, csq2, csq2.getBoost(), ConstantScoreQuery.ConstantScoreScorer.class.getName(), TermScorer.class.getName());
// for the combined BQ, the scorer should always be BooleanScorer's BucketScorer, because our scorer supports out-of order collection!
final String bucketScorerClass = FakeScorer.class.getName();