You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/02/21 15:26:08 UTC

svn commit: r1661367 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/search/ConstantScoreQuery.java core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java

Author: jpountz
Date: Sat Feb 21 14:26:08 2015
New Revision: 1661367

URL: http://svn.apache.org/r1661367
Log:
LUCENE-6262: Don't wrap the inner weight in ConstantScoreQuery when scores are not required.

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1661367&r1=1661366&r2=1661367&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Sat Feb 21 14:26:08 2015
@@ -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()

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java?rev=1661367&r1=1661366&r2=1661367&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java Sat Feb 21 14:26:08 2015
@@ -78,9 +78,9 @@ public class ConstantScoreQuery extends
     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
 
   @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

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java?rev=1661367&r1=1661366&r2=1661367&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java Sat Feb 21 14:26:08 2015
@@ -115,8 +115,8 @@ public class TestConstantScoreQuery exte
       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();