LUCENE-3213: Move CustomScoreProvider over to AtomicReaderContext

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1137176 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2011-06-18 11:59:24 +00:00
parent 40f5948b3d
commit b6d0c850aa
4 changed files with 28 additions and 28 deletions

View File

@ -26,7 +26,7 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericField; import org.apache.lucene.document.NumericField;
import org.apache.lucene.index.IndexWriter; 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.index.Term;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
@ -222,8 +222,8 @@ public class TestCartesian extends LuceneTestCase {
CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){ CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
@Override @Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
return new CustomScoreProvider(reader) { return new CustomScoreProvider(context) {
@Override // TODO: broken, as reader is not used! @Override // TODO: broken, as reader is not used!
public float customScore(int doc, float subQueryScore, float valSrcScore){ public float customScore(int doc, float subQueryScore, float valSrcScore){
if (VERBOSE) System.out.println(doc); if (VERBOSE) System.out.println(doc);
@ -318,8 +318,8 @@ public class TestCartesian extends LuceneTestCase {
CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){ CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
@Override @Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
return new CustomScoreProvider(reader) { return new CustomScoreProvider(context) {
@Override // TODO: broken, as reader is not used! @Override // TODO: broken, as reader is not used!
public float customScore(int doc, float subQueryScore, float valSrcScore){ public float customScore(int doc, float subQueryScore, float valSrcScore){
if (VERBOSE) System.out.println(doc); if (VERBOSE) System.out.println(doc);
@ -415,8 +415,8 @@ public class TestCartesian extends LuceneTestCase {
CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){ CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
@Override @Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
return new CustomScoreProvider(reader) { return new CustomScoreProvider(context) {
@Override // TODO: broken, as reader is not used! @Override // TODO: broken, as reader is not used!
public float customScore(int doc, float subQueryScore, float valSrcScore){ public float customScore(int doc, float subQueryScore, float valSrcScore){
if (VERBOSE) System.out.println(doc); if (VERBOSE) System.out.println(doc);
@ -510,8 +510,8 @@ public class TestCartesian extends LuceneTestCase {
FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT); FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
CustomScoreQuery customScore = new CustomScoreQuery(tq,fsQuery){ CustomScoreQuery customScore = new CustomScoreQuery(tq,fsQuery){
@Override @Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
return new CustomScoreProvider(reader) { return new CustomScoreProvider(context) {
@Override // TODO: broken, as reader is not used! @Override // TODO: broken, as reader is not used!
public float customScore(int doc, float subQueryScore, float valSrcScore){ public float customScore(int doc, float subQueryScore, float valSrcScore){
if (VERBOSE) System.out.println(doc); if (VERBOSE) System.out.println(doc);

View File

@ -19,7 +19,7 @@ package org.apache.lucene.search.function;
import java.io.IOException; 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.Explanation;
import org.apache.lucene.search.FieldCache; // for javadocs import org.apache.lucene.search.FieldCache; // for javadocs
@ -37,13 +37,13 @@ import org.apache.lucene.search.FieldCache; // for javadocs
*/ */
public class CustomScoreProvider { public class CustomScoreProvider {
protected final IndexReader reader; protected final AtomicReaderContext context;
/** /**
* Creates a new instance of the provider class for the given {@link IndexReader}. * Creates a new instance of the provider class for the given {@link IndexReader}.
*/ */
public CustomScoreProvider(IndexReader reader) { public CustomScoreProvider(AtomicReaderContext context) {
this.reader = reader; this.context = context;
} }
/** /**

View File

@ -175,8 +175,8 @@ public class CustomScoreQuery extends Query {
* implementation as specified in the docs of {@link CustomScoreProvider}. * implementation as specified in the docs of {@link CustomScoreProvider}.
* @since 2.9.2 * @since 2.9.2
*/ */
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) throws IOException { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) throws IOException {
return new CustomScoreProvider(reader); return new CustomScoreProvider(context);
} }
//=========================== W E I G H T ============================ //=========================== W E I G H T ============================
@ -251,7 +251,7 @@ public class CustomScoreQuery extends Query {
for(int i = 0; i < valSrcScorers.length; i++) { for(int i = 0; i < valSrcScorers.length; i++) {
valSrcScorers[i] = valSrcWeights[i].scorer(context, scorerContext.scoreDocsInOrder(true)); 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 @Override
@ -270,7 +270,7 @@ public class CustomScoreQuery extends Query {
for(int i = 0; i < valSrcWeights.length; i++) { for(int i = 0; i < valSrcWeights.length; i++) {
valSrcExpls[i] = valSrcWeights[i].explain(info, doc); 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(); float sc = getValue() * customExp.getValue();
Explanation res = new ComplexExplanation( Explanation res = new ComplexExplanation(
true, sc, CustomScoreQuery.this.toString() + ", product of:"); 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 private float vScores[]; // reused in score() to avoid allocating this array for each doc
// constructor // constructor
private CustomScorer(IndexReader reader, CustomWeight w, private CustomScorer(CustomScoreProvider provider, CustomWeight w,
Scorer subQueryScorer, Scorer[] valSrcScorers) throws IOException { Scorer subQueryScorer, Scorer[] valSrcScorers) throws IOException {
super(w); super(w);
this.qWeight = w.getValue(); this.qWeight = w.getValue();
this.subQueryScorer = subQueryScorer; this.subQueryScorer = subQueryScorer;
this.valSrcScorers = valSrcScorers; this.valSrcScorers = valSrcScorers;
this.vScores = new float[valSrcScorers.length]; this.vScores = new float[valSrcScorers.length];
this.provider = CustomScoreQuery.this.getCustomScoreProvider(reader); this.provider = provider;
} }
@Override @Override

View File

@ -26,7 +26,7 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
/** /**
@ -95,8 +95,8 @@ public class TestCustomScoreQuery extends FunctionTestSetup {
} }
@Override @Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
return new CustomScoreProvider(reader) { return new CustomScoreProvider(context) {
@Override @Override
public float customScore(int doc, float subQueryScore, float valSrcScore) { public float customScore(int doc, float subQueryScore, float valSrcScore) {
return subQueryScore + valSrcScore; return subQueryScore + valSrcScore;
@ -130,8 +130,8 @@ public class TestCustomScoreQuery extends FunctionTestSetup {
} }
@Override @Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
return new CustomScoreProvider(reader) { return new CustomScoreProvider(context) {
@Override @Override
public float customScore(int doc, float subQueryScore, float valSrcScores[]) { public float customScore(int doc, float subQueryScore, float valSrcScores[]) {
if (valSrcScores.length == 0) { if (valSrcScores.length == 0) {
@ -169,12 +169,12 @@ public class TestCustomScoreQuery extends FunctionTestSetup {
private final class CustomExternalQuery extends CustomScoreQuery { private final class CustomExternalQuery extends CustomScoreQuery {
@Override @Override
protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) throws IOException { protected CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) throws IOException {
final int[] values = FieldCache.DEFAULT.getInts(reader, INT_FIELD); final int[] values = FieldCache.DEFAULT.getInts(context.reader, INT_FIELD);
return new CustomScoreProvider(reader) { return new CustomScoreProvider(context) {
@Override @Override
public float customScore(int doc, float subScore, float valSrcScore) throws IOException { public float customScore(int doc, float subScore, float valSrcScore) throws IOException {
assertTrue(doc <= reader.maxDoc()); assertTrue(doc <= context.reader.maxDoc());
return values[doc]; return values[doc];
} }
}; };