|
@@ -15,20 +15,21 @@ import org.apache.lucene.search.Explanation;
|
|
|
import org.apache.lucene.search.IndexSearcher;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
|
* A {@link DoubleValuesSource} which has a stub {@link DoubleValues} that holds a dynamically replaceable constant double.
|
|
|
*/
|
|
|
final class ReplaceableConstDoubleValueSource extends DoubleValuesSource {
|
|
|
- final ReplaceableConstDoubleValues fv;
|
|
|
|
|
|
- ReplaceableConstDoubleValueSource() {
|
|
|
- fv = new ReplaceableConstDoubleValues();
|
|
|
- }
|
|
|
+ private final Map<LeafReaderContext, ReplaceableConstDoubleValues> specialValues = new ConcurrentHashMap<>();
|
|
|
|
|
|
@Override
|
|
|
public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
|
|
|
- return fv;
|
|
|
+ ReplaceableConstDoubleValues replaceableConstDoubleValues = new ReplaceableConstDoubleValues();
|
|
|
+ specialValues.put(ctx, replaceableConstDoubleValues);
|
|
|
+ return replaceableConstDoubleValues;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -38,8 +39,12 @@ final class ReplaceableConstDoubleValueSource extends DoubleValuesSource {
|
|
|
|
|
|
@Override
|
|
|
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
|
|
- if (fv.advanceExact(docId)) return Explanation.match((float) fv.doubleValue(), "ReplaceableConstDoubleValues");
|
|
|
- else return Explanation.noMatch("ReplaceableConstDoubleValues");
|
|
|
+ // TODO where is this explain called? I bet it's never tested, and probably never called.
|
|
|
+ ReplaceableConstDoubleValues fv = specialValues.get(ctx);
|
|
|
+ if (fv.advanceExact(docId)) {
|
|
|
+ return Explanation.match((float) fv.doubleValue(), "ReplaceableConstDoubleValues");
|
|
|
+ }
|
|
|
+ return Explanation.noMatch("ReplaceableConstDoubleValues");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -52,7 +57,9 @@ final class ReplaceableConstDoubleValueSource extends DoubleValuesSource {
|
|
|
return System.identityHashCode(this);
|
|
|
}
|
|
|
|
|
|
- public void setValue(double v) {
|
|
|
+ public void setValue(LeafReaderContext ctx, double v) {
|
|
|
+ ReplaceableConstDoubleValues fv = specialValues.get(ctx);
|
|
|
+ assert fv != null : "getValues must be called before setValue for any given leaf reader context";
|
|
|
fv.setValue(v);
|
|
|
}
|
|
|
|