mirror of https://github.com/apache/lucene.git
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:
parent
40f5948b3d
commit
b6d0c850aa
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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) {
|
||||
@Override
|
||||
public 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) {
|
||||
@Override
|
||||
public 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) {
|
||||
@Override
|
||||
public float customScore(int doc, float subScore, float valSrcScore) throws IOException {
|
||||
assertTrue(doc <= reader.maxDoc());
|
||||
assertTrue(doc <= context.reader.maxDoc());
|
||||
return values[doc];
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue