Apache Solr open-source search software
LUCENE-3213: Move CustomScoreProvider over to AtomicReaderContext
Uwe Schindlerb6d0c850aa62
diff --git a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.javaindex 06bb23fa35e..c3abb7b0d6e 100644--- a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java+++ b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java@@ -26,7 +26,7 @@ import org.apache.lucene.document.Document;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 LuceneTestCase {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 LuceneTestCase {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 LuceneTestCase {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 LuceneTestCase {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);diff --git a/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java b/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.javaindex 2af0187f104..e956707afe9 100644--- a/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java+++ b/lucene/src/java/org/apache/lucene/search/function/CustomScoreProvider.java@@ -19,7 +19,7 @@ package org.apache.lucene.search.function;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.FieldCache; // for javadocs*/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;}/**diff --git a/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java b/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.javaindex 9ea258f30c6..2de9509d312 100755--- a/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java+++ b/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java@@ -175,8 +175,8 @@ public class CustomScoreQuery extends Query {* 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 Query {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 Query {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 Query {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;}@Overridediff --git a/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java b/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.javaindex 137a84b7ce2..fed4beeeacd 100755--- a/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java+++ b/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java@@ -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 extends FunctionTestSetup {}@Override- protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {- return new CustomScoreProvider(reader) {+ protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {+ return new CustomScoreProvider(context) {@Overridepublic float customScore(int doc, float subQueryScore, float valSrcScore) {return subQueryScore + valSrcScore;@@ -130,8 +130,8 @@ public class TestCustomScoreQuery extends FunctionTestSetup {}@Override- protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {- return new CustomScoreProvider(reader) {+ protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {+ return new CustomScoreProvider(context) {@Overridepublic float customScore(int doc, float subQueryScore, float valSrcScores[]) {if (valSrcScores.length == 0) {@@ -169,12 +169,12 @@ public class TestCustomScoreQuery extends FunctionTestSetup {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) {@Overridepublic float customScore(int doc, float subScore, float valSrcScore) throws IOException {- assertTrue(doc <= reader.maxDoc());+ assertTrue(doc <= context.reader.maxDoc());return values[doc];}};