You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2011/06/18 13:59:24 UTC

svn commit: r1137176 - in /lucene/dev/trunk/lucene: contrib/spatial/src/test/org/apache/lucene/spatial/tier/ src/java/org/apache/lucene/search/function/ src/test/org/apache/lucene/search/function/

Author: uschindler
Date: Sat Jun 18 11:59:24 2011
New Revision: 1137176

URL: http://svn.apache.org/viewvc?rev=1137176&view=rev
Log:
LUCENE-3213: Move CustomScoreProvider over to AtomicReaderContext

Modified:
    lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java

Modified: lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java?rev=1137176&r1=1137175&r2=1137176&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java (original)
+++ lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java Sat Jun 18 11:59:24 2011
@@ -26,7 +26,7 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.NumericField;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
@@ -222,8 +222,8 @@ public class TestCartesian extends Lucen
     CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
 
       @Override
-      protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
-        return new CustomScoreProvider(reader) {
+      protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
+        return new CustomScoreProvider(context) {
           @Override // TODO: broken, as reader is not used!
           public float customScore(int doc, float subQueryScore, float valSrcScore){
             if (VERBOSE) System.out.println(doc);
@@ -318,8 +318,8 @@ public class TestCartesian extends Lucen
     CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
 
       @Override
-      protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
-        return new CustomScoreProvider(reader) {
+      protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
+        return new CustomScoreProvider(context) {
           @Override // TODO: broken, as reader is not used!
           public float customScore(int doc, float subQueryScore, float valSrcScore){
             if (VERBOSE) System.out.println(doc);
@@ -415,8 +415,8 @@ public class TestCartesian extends Lucen
     
       CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
         @Override
-        protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
-          return new CustomScoreProvider(reader) {
+        protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
+          return new CustomScoreProvider(context) {
             @Override // TODO: broken, as reader is not used!
             public float customScore(int doc, float subQueryScore, float valSrcScore){
               if (VERBOSE) System.out.println(doc);
@@ -510,8 +510,8 @@ public class TestCartesian extends Lucen
       FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
       CustomScoreQuery customScore = new CustomScoreQuery(tq,fsQuery){
         @Override
-        protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
-          return new CustomScoreProvider(reader) {
+        protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
+          return new CustomScoreProvider(context) {
               @Override // TODO: broken, as reader is not used!
               public float customScore(int doc, float subQueryScore, float valSrcScore){
               if (VERBOSE) System.out.println(doc);

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java?rev=1137176&r1=1137175&r2=1137176&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java Sat Jun 18 11:59:24 2011
@@ -19,7 +19,7 @@ package org.apache.lucene.search.functio
 
 import java.io.IOException;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.FieldCache; // for javadocs
 
@@ -37,13 +37,13 @@ import org.apache.lucene.search.FieldCac
  */
 public class CustomScoreProvider {
 
-  protected final IndexReader reader;
+  protected final AtomicReaderContext context;
 
   /**
    * Creates a new instance of the provider class for the given {@link IndexReader}.
    */
-  public CustomScoreProvider(IndexReader reader) {
-    this.reader = reader;
+  public CustomScoreProvider(AtomicReaderContext context) {
+    this.context = context;
   }
 
   /**

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java?rev=1137176&r1=1137175&r2=1137176&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java Sat Jun 18 11:59:24 2011
@@ -175,8 +175,8 @@ public class CustomScoreQuery extends Qu
    * implementation as specified in the docs of {@link CustomScoreProvider}.
    * @since 2.9.2
    */
-  protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) throws IOException {
-    return new CustomScoreProvider(reader);
+  protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) throws IOException {
+    return new CustomScoreProvider(context);
   }
 
   //=========================== W E I G H T ============================
@@ -251,7 +251,7 @@ public class CustomScoreQuery extends Qu
       for(int i = 0; i < valSrcScorers.length; i++) {
          valSrcScorers[i] = valSrcWeights[i].scorer(context, scorerContext.scoreDocsInOrder(true));
       }
-      return new CustomScorer(context.reader, this, subQueryScorer, valSrcScorers);
+      return new CustomScorer(CustomScoreQuery.this.getCustomScoreProvider(context), this, subQueryScorer, valSrcScorers);
     }
 
     @Override
@@ -270,7 +270,7 @@ public class CustomScoreQuery extends Qu
       for(int i = 0; i < valSrcWeights.length; i++) {
         valSrcExpls[i] = valSrcWeights[i].explain(info, doc);
       }
-      Explanation customExp = CustomScoreQuery.this.getCustomScoreProvider(info.reader).customExplain(doc,subQueryExpl,valSrcExpls);
+      Explanation customExp = CustomScoreQuery.this.getCustomScoreProvider(info).customExplain(doc,subQueryExpl,valSrcExpls);
       float sc = getValue() * customExp.getValue();
       Explanation res = new ComplexExplanation(
         true, sc, CustomScoreQuery.this.toString() + ", product of:");
@@ -300,14 +300,14 @@ public class CustomScoreQuery extends Qu
     private float vScores[]; // reused in score() to avoid allocating this array for each doc 
 
     // constructor
-    private CustomScorer(IndexReader reader, CustomWeight w,
+    private CustomScorer(CustomScoreProvider provider, CustomWeight w,
         Scorer subQueryScorer, Scorer[] valSrcScorers) throws IOException {
       super(w);
       this.qWeight = w.getValue();
       this.subQueryScorer = subQueryScorer;
       this.valSrcScorers = valSrcScorers;
       this.vScores = new float[valSrcScorers.length];
-      this.provider = CustomScoreQuery.this.getCustomScoreProvider(reader);
+      this.provider = provider;
     }
 
     @Override

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java?rev=1137176&r1=1137175&r2=1137176&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java Sat Jun 18 11:59:24 2011
@@ -26,7 +26,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.index.Term;
 
 /**
@@ -95,8 +95,8 @@ public class TestCustomScoreQuery extend
     }
     
     @Override
-    protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
-      return new CustomScoreProvider(reader) {
+    protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
+      return new CustomScoreProvider(context) {
         @Override
         public float customScore(int doc, float subQueryScore, float valSrcScore) {
           return subQueryScore + valSrcScore;
@@ -130,8 +130,8 @@ public class TestCustomScoreQuery extend
     }
 
     @Override
-    protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
-      return new CustomScoreProvider(reader) {
+    protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
+      return new CustomScoreProvider(context) {
         @Override
         public float customScore(int doc, float subQueryScore, float valSrcScores[]) {
           if (valSrcScores.length == 0) {
@@ -169,12 +169,12 @@ public class TestCustomScoreQuery extend
   private final class CustomExternalQuery extends CustomScoreQuery {
 
     @Override
-    protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) throws IOException {
-      final int[] values = FieldCache.DEFAULT.getInts(reader, INT_FIELD);
-      return new CustomScoreProvider(reader) {
+    protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) throws IOException {
+      final int[] values = FieldCache.DEFAULT.getInts(context.reader, INT_FIELD);
+      return new CustomScoreProvider(context) {
         @Override
         public float customScore(int doc, float subScore, float valSrcScore) throws IOException {
-          assertTrue(doc <= reader.maxDoc());
+          assertTrue(doc <= context.reader.maxDoc());
           return values[doc];
         }
       };