From c1030eeb74e7d5ef6dc36173add6e9da5da645fe Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 13 Dec 2017 16:21:14 +0000 Subject: [PATCH] LUCENE-8012: Explanation takes Number rather than float --- lucene/CHANGES.txt | 3 ++ .../lucene/search/DisjunctionMaxQuery.java | 4 +- .../lucene/search/DoubleValuesSource.java | 8 +-- .../org/apache/lucene/search/Explanation.java | 14 ++--- .../apache/lucene/search/QueryRescorer.java | 6 +-- .../apache/lucene/search/SortRescorer.java | 2 +- .../lucene/search/similarities/Axiomatic.java | 13 ++--- .../search/similarities/BM25Similarity.java | 10 ++-- .../search/similarities/DFISimilarity.java | 6 +-- .../search/similarities/DFRSimilarity.java | 4 +- .../search/similarities/IBSimilarity.java | 6 +-- .../similarities/LMDirichletSimilarity.java | 4 +- .../LMJelinekMercerSimilarity.java | 4 +- .../search/similarities/MultiSimilarity.java | 2 +- .../search/similarities/Similarity.java | 2 +- .../search/similarities/SimilarityBase.java | 4 +- .../search/similarities/TFIDFSimilarity.java | 8 +-- .../lucene/search/TestBooleanQuery.java | 2 +- .../lucene/search/TestDocValuesScoring.java | 2 +- .../lucene/search/TestQueryRescorer.java | 4 +- .../search/similarities/TestSimilarity2.java | 2 +- .../similarities/TestSimilarityBase.java | 2 +- .../lucene/search/spans/TestBasics.java | 54 +++++++++---------- .../search/spans/TestNearSpansOrdered.java | 2 +- .../expressions/ExpressionValueSource.java | 4 +- .../search/join/ToParentBlockJoinQuery.java | 2 +- .../lucene/search/join/TestBlockJoin.java | 4 +- .../lucene/search/join/TestJoinUtil.java | 2 +- .../lucene/misc/SweetSpotSimilarityTest.java | 2 +- .../queries/function/FunctionQuery.java | 6 +-- .../lucene/queries/function/ValueSource.java | 2 +- .../queries/payloads/PayloadScoreQuery.java | 4 +- .../TestFunctionScoreExplanations.java | 10 ++-- .../function/TestFunctionScoreQuery.java | 4 +- .../payloads/TestPayloadCheckQuery.java | 2 +- .../apache/lucene/search/CoveringQuery.java | 2 +- .../bbox/BBoxSimilarityValueSource.java | 2 +- .../util/ReciprocalDoubleValuesSource.java | 2 +- .../org/apache/lucene/search/CheckHits.java | 4 +- .../similarities/AssertingSimilarity.java | 6 +-- .../similarities/BaseSimilarityTestCase.java | 8 +-- .../search/TestBaseExplanationTestCase.java | 2 +- .../apache/solr/ltr/model/LinearModel.java | 2 +- .../ltr/model/MultipleAdditiveTreesModel.java | 2 +- .../org/apache/solr/ltr/norm/Normalizer.java | 2 +- .../org/apache/solr/schema/LatLonType.java | 2 +- .../TestSweetSpotSimilarityFactory.java | 2 +- 47 files changed, 125 insertions(+), 121 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 0ec795a212b..ff948094c88 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -29,6 +29,9 @@ API Changes * LUCENE-8099: CustomScoreQuery, BoostedQuery and BoostingQuery have been removed (Alan Woodward) +* LUCENE-8012: Explanation now takes Number rather than float (Alan Woodward, + Robert Muir) + Changes in Runtime Behavior * LUCENE-7837: Indices that were created before the previous major version diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java index 3285bafccd1..1e67cb15046 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java @@ -159,7 +159,7 @@ public final class DisjunctionMaxQuery extends Query implements Iterable @Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { boolean match = false; - float max = 0; + double max = 0; double otherSum = 0; List subs = new ArrayList<>(); for (Weight wt : weights) { @@ -167,7 +167,7 @@ public final class DisjunctionMaxQuery extends Query implements Iterable if (e.isMatch()) { match = true; subs.add(e); - float score = e.getValue(); + double score = e.getValue().doubleValue(); if (score >= max) { otherSum += max; max = score; diff --git a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java index d5d19ec7695..3938d3f9ba2 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java +++ b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java @@ -68,9 +68,9 @@ public abstract class DoubleValuesSource implements SegmentCacheable { * @throws IOException if an {@link IOException} occurs */ public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { - DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue()).getValues(ctx, null)); + DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue().doubleValue()).getValues(ctx, null)); if (dv.advanceExact(docId)) - return Explanation.match((float) dv.doubleValue(), this.toString()); + return Explanation.match(dv.doubleValue(), this.toString()); return Explanation.noMatch(this.toString()); } @@ -305,7 +305,7 @@ public abstract class DoubleValuesSource implements SegmentCacheable { @Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) { - return Explanation.match((float) value, "constant(" + value + ")"); + return Explanation.match(value, "constant(" + value + ")"); } @Override @@ -405,7 +405,7 @@ public abstract class DoubleValuesSource implements SegmentCacheable { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { DoubleValues values = getValues(ctx, null); if (values.advanceExact(docId)) - return Explanation.match((float) values.doubleValue(), this.toString()); + return Explanation.match(values.doubleValue(), this.toString()); else return Explanation.noMatch(this.toString()); } diff --git a/lucene/core/src/java/org/apache/lucene/search/Explanation.java b/lucene/core/src/java/org/apache/lucene/search/Explanation.java index 42e3ce70624..f5d2ec40a51 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Explanation.java +++ b/lucene/core/src/java/org/apache/lucene/search/Explanation.java @@ -32,7 +32,7 @@ public final class Explanation { * @param description how {@code value} was computed * @param details sub explanations that contributed to this explanation */ - public static Explanation match(float value, String description, Collection details) { + public static Explanation match(Number value, String description, Collection details) { return new Explanation(true, value, description, details); } @@ -42,7 +42,7 @@ public final class Explanation { * @param description how {@code value} was computed * @param details sub explanations that contributed to this explanation */ - public static Explanation match(float value, String description, Explanation... details) { + public static Explanation match(Number value, String description, Explanation... details) { return new Explanation(true, value, description, Arrays.asList(details)); } @@ -61,14 +61,14 @@ public final class Explanation { } private final boolean match; // whether the document matched - private final float value; // the value of this node + private final Number value; // the value of this node private final String description; // what it represents private final List details; // sub-explanations /** Create a new explanation */ - private Explanation(boolean match, float value, String description, Collection details) { + private Explanation(boolean match, Number value, String description, Collection details) { this.match = match; - this.value = value; + this.value = Objects.requireNonNull(value); this.description = Objects.requireNonNull(description); this.details = Collections.unmodifiableList(new ArrayList<>(details)); for (Explanation detail : details) { @@ -84,7 +84,7 @@ public final class Explanation { } /** The value assigned to this explanation node. */ - public float getValue() { return value; } + public Number getValue() { return value; } /** A description of this explanation node. */ public String getDescription() { return description; } @@ -126,7 +126,7 @@ public final class Explanation { if (o == null || getClass() != o.getClass()) return false; Explanation that = (Explanation) o; return match == that.match && - Float.compare(that.value, value) == 0 && + Objects.equals(value, that.value) && Objects.equals(description, that.description) && Objects.equals(details, that.details); } diff --git a/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java b/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java index b264d72d595..6b19f295a7d 100644 --- a/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java @@ -141,13 +141,13 @@ public abstract class QueryRescorer extends Rescorer { public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { Explanation secondPassExplanation = searcher.explain(query, docID); - Float secondPassScore = secondPassExplanation.isMatch() ? secondPassExplanation.getValue() : null; + Number secondPassScore = secondPassExplanation.isMatch() ? secondPassExplanation.getValue() : null; float score; if (secondPassScore == null) { - score = combine(firstPassExplanation.getValue(), false, 0.0f); + score = combine(firstPassExplanation.getValue().floatValue(), false, 0.0f); } else { - score = combine(firstPassExplanation.getValue(), true, secondPassScore.floatValue()); + score = combine(firstPassExplanation.getValue().floatValue(), true, secondPassScore.floatValue()); } Explanation first = Explanation.match(firstPassExplanation.getValue(), "first pass score", firstPassExplanation); diff --git a/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java b/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java index d3912ddb934..b83e233187e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java @@ -95,7 +95,7 @@ public class SortRescorer extends Rescorer { @Override public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { - TopDocs oneHit = new TopDocs(1, new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue())}); + TopDocs oneHit = new TopDocs(1, new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue().floatValue())}); TopDocs hits = rescore(searcher, oneHit, 1); assert hits.totalHits == 1; diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/Axiomatic.java b/lucene/core/src/java/org/apache/lucene/search/similarities/Axiomatic.java index df683c14f90..1522e5dc3c5 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/Axiomatic.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/Axiomatic.java @@ -122,13 +122,14 @@ public abstract class Axiomatic extends SimilarityBase { protected Explanation explain( BasicStats stats, int doc, Explanation freq, double docLen) { List subs = new ArrayList<>(); - explain(subs, stats, doc, freq.getValue(), docLen); + double f = freq.getValue().doubleValue(); + explain(subs, stats, doc, f, docLen); - double score = tf(stats, freq.getValue(), docLen) - * ln(stats, freq.getValue(), docLen) - * tfln(stats, freq.getValue(), docLen) - * idf(stats, freq.getValue(), docLen) - - gamma(stats, freq.getValue(), docLen); + double score = tf(stats, f, docLen) + * ln(stats, f, docLen) + * tfln(stats, f, docLen) + * idf(stats, f, docLen) + - gamma(stats, f, docLen); Explanation explanation = Explanation.match((float) score, "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), computed from:", diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java index c9208919164..dce156bc060 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java @@ -170,7 +170,7 @@ public class BM25Similarity extends Similarity { for (final TermStatistics stat : termStats ) { Explanation idfExplain = idfExplain(collectionStats, stat); details.add(idfExplain); - idf += idfExplain.getValue(); + idf += idfExplain.getValue().floatValue(); } return Explanation.match((float) idf, "idf, sum of:", details); } @@ -236,7 +236,7 @@ public class BM25Similarity extends Similarity { subs.addAll(stats.explain()); Explanation tfExpl = explainTF(doc, freq); subs.add(tfExpl); - return Explanation.match(stats.weight * tfExpl.getValue(), + return Explanation.match(stats.weight * tfExpl.getValue().floatValue(), "score(doc="+doc+",freq="+freq.getValue()+"), product of:", subs); } @@ -247,7 +247,7 @@ public class BM25Similarity extends Similarity { if (norms == null) { subs.add(Explanation.match(0, "b, field omits length norms")); return Explanation.match( - (float) (freq.getValue() / (freq.getValue() + (double) k1)), + (float) (freq.getValue().floatValue() / (freq.getValue().floatValue() + (double) k1)), "tf, computed as freq / (freq + k1) from:", subs); } else { boolean found = norms.advanceExact(doc); @@ -263,7 +263,7 @@ public class BM25Similarity extends Similarity { subs.add(Explanation.match(stats.avgdl, "avgdl, average length of field")); float normValue = k1 * ((1 - b) + b * doclen / stats.avgdl); return Explanation.match( - (float) (freq.getValue() / (freq.getValue() + (double) normValue)), + (float) (freq.getValue().floatValue() / (freq.getValue().floatValue() + (double) normValue)), "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:", subs); } } @@ -294,7 +294,7 @@ public class BM25Similarity extends Similarity { this.avgdl = avgdl; this.k1 = k1; this.cache = cache; - this.weight = (k1 + 1) * boost * idf.getValue(); + this.weight = (k1 + 1) * boost * idf.getValue().floatValue(); } private List explain() { diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/DFISimilarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/DFISimilarity.java index 6ebe9cb8340..66f22be0aea 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/DFISimilarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/DFISimilarity.java @@ -82,7 +82,7 @@ public class DFISimilarity extends SimilarityBase { BasicStats stats, int doc, Explanation freq, double docLen) { final double expected = (stats.getTotalTermFreq() + 1) * docLen / (stats.getNumberOfFieldTokens() + 1); - if (freq.getValue() <= expected){ + if (freq.getValue().doubleValue() <= expected){ return Explanation.match((float) 0, "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), equals to 0"); @@ -95,14 +95,14 @@ public class DFISimilarity extends SimilarityBase { Explanation.match(stats.getNumberOfFieldTokens(), "T, total number of tokens in the field")); - final double measure = independence.score(freq.getValue(), expected); + final double measure = independence.score(freq.getValue().doubleValue(), expected); Explanation explMeasure = Explanation.match((float) measure, "measure, computed as independence.score(freq, expected) from:", freq, explExpected); return Explanation.match( - (float) score(stats, freq.getValue(), docLen), + (float) score(stats, freq.getValue().doubleValue(), docLen), "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), computed as boost * log2(measure + 1) from:", Explanation.match( (float)stats.getBoost(), "boost, query boost"), diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java index 8c73e6eb271..a41e35cbcf9 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java @@ -138,10 +138,10 @@ public class DFRSimilarity extends SimilarityBase { protected Explanation explain( BasicStats stats, int doc, Explanation freq, double docLen) { List subs = new ArrayList<>(); - explain(subs, stats, doc, freq.getValue(), docLen); + explain(subs, stats, doc, freq.getValue().doubleValue(), docLen); return Explanation.match( - (float) score(stats, freq.getValue(), docLen), + (float) score(stats, freq.getValue().doubleValue(), docLen), "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), computed as boost * " + "basicModel.score(stats, tfn) * afterEffect.score(stats, tfn) from:", diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java index 3e9ba0c4c32..9a576085f67 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java @@ -120,17 +120,17 @@ public class IBSimilarity extends SimilarityBase { Explanation lambdaExpl = lambda.explain(stats); subs.add(normExpl); subs.add(lambdaExpl); - subs.add(distribution.explain(stats, normExpl.getValue(), lambdaExpl.getValue())); + subs.add(distribution.explain(stats, normExpl.getValue().floatValue(), lambdaExpl.getValue().floatValue())); } @Override protected Explanation explain( BasicStats stats, int doc, Explanation freq, double docLen) { List subs = new ArrayList<>(); - explain(subs, stats, doc, freq.getValue(), docLen); + explain(subs, stats, doc, freq.getValue().doubleValue(), docLen); return Explanation.match( - (float) score(stats, freq.getValue(), docLen), + (float) score(stats, freq.getValue().doubleValue(), docLen), "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), computed as boost * " + "distribution.score(stats, normalization.tfn(stats, freq," + diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java index be7329bec23..c12cba451dc 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java @@ -114,10 +114,10 @@ public class LMDirichletSimilarity extends LMSimilarity { protected Explanation explain( BasicStats stats, int doc, Explanation freq, double docLen) { List subs = new ArrayList<>(); - explain(subs, stats, doc, freq.getValue(), docLen); + explain(subs, stats, doc, freq.getValue().doubleValue(), docLen); return Explanation.match( - (float) score(stats, freq.getValue(), docLen), + (float) score(stats, freq.getValue().doubleValue(), docLen), "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), computed as boost * " + "(term weight + document norm) from:", diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java index f6db238d44b..42e5a7bc319 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java @@ -95,10 +95,10 @@ public class LMJelinekMercerSimilarity extends LMSimilarity { protected Explanation explain( BasicStats stats, int doc, Explanation freq, double docLen) { List subs = new ArrayList<>(); - explain(subs, stats, doc, freq.getValue(), docLen); + explain(subs, stats, doc, freq.getValue().doubleValue(), docLen); return Explanation.match( - (float) score(stats, freq.getValue(), docLen), + (float) score(stats, freq.getValue().doubleValue(), docLen), "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), computed as boost * " + "log(1 + ((1 - lambda) * freq / dl) /(lambda * P)) from:", diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java index cbd61dd255d..2f48cc69333 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java @@ -97,7 +97,7 @@ public class MultiSimilarity extends Similarity { for (SimScorer subScorer : subScorers) { subs.add(subScorer.explain(doc, freq)); } - return Explanation.match(score(doc, freq.getValue()), "sum of:", subs); + return Explanation.match(score(doc, freq.getValue().floatValue()), "sum of:", subs); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java index 30895eb7420..5f0bcd0bcb2 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java @@ -173,7 +173,7 @@ public abstract class Similarity { */ public Explanation explain(int doc, Explanation freq) throws IOException { return Explanation.match( - score(doc, freq.getValue()), + score(doc, freq.getValue().floatValue()), "score(doc=" + doc + ",freq=" + freq.getValue() +"), with freq of:", Collections.singleton(freq)); } diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/SimilarityBase.java b/lucene/core/src/java/org/apache/lucene/search/similarities/SimilarityBase.java index 99a2e36efc3..f227f38fd36 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/SimilarityBase.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/SimilarityBase.java @@ -162,10 +162,10 @@ public abstract class SimilarityBase extends Similarity { protected Explanation explain( BasicStats stats, int doc, Explanation freq, double docLen) { List subs = new ArrayList<>(); - explain(subs, stats, doc, freq.getValue(), docLen); + explain(subs, stats, doc, freq.getValue().floatValue(), docLen); return Explanation.match( - (float) score(stats, freq.getValue(), docLen), + (float) score(stats, freq.getValue().floatValue(), docLen), "score(" + getClass().getSimpleName() + ", doc=" + doc + ", freq=" + freq.getValue() +"), computed from:", subs); } diff --git a/lucene/core/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java b/lucene/core/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java index 51e6278f315..0452371abdc 100644 --- a/lucene/core/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java +++ b/lucene/core/src/java/org/apache/lucene/search/similarities/TFIDFSimilarity.java @@ -472,7 +472,7 @@ public abstract class TFIDFSimilarity extends Similarity { for (final TermStatistics stat : termStats ) { Explanation idfExplain = idfExplain(collectionStats, stat); subs.add(idfExplain); - idf += idfExplain.getValue(); + idf += idfExplain.getValue().floatValue(); } return Explanation.match((float) idf, "idf(), sum of:", subs); } @@ -595,7 +595,7 @@ public abstract class TFIDFSimilarity extends Similarity { this.field = field; this.idf = idf; this.boost = boost; - this.queryWeight = boost * idf.getValue(); + this.queryWeight = boost * idf.getValue().floatValue(); this.normTable = normTable; } } @@ -606,7 +606,7 @@ public abstract class TFIDFSimilarity extends Similarity { subs.add(Explanation.match(stats.boost, "boost")); } subs.add(stats.idf); - Explanation tf = Explanation.match(tf(freq.getValue()), "tf(freq="+freq.getValue()+"), with freq of:", freq); + Explanation tf = Explanation.match(tf(freq.getValue().floatValue()), "tf(freq="+freq.getValue()+"), with freq of:", freq); subs.add(tf); float norm; @@ -624,7 +624,7 @@ public abstract class TFIDFSimilarity extends Similarity { subs.add(fieldNorm); return Explanation.match( - stats.queryWeight * tf.getValue() * norm, + stats.queryWeight * tf.getValue().floatValue() * norm, "score(doc="+doc+",freq="+freq.getValue()+"), product of:", subs); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java index c479a8c6bf2..2dd77385388 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java @@ -523,7 +523,7 @@ public class TestBooleanQuery extends LuceneTestCase { @Override public void collect(int doc) throws IOException { final float actualScore = scorer.score(); - final float expectedScore = searcher.explain(bq2, docBase + doc).getValue(); + final float expectedScore = searcher.explain(bq2, docBase + doc).getValue().floatValue(); assertEquals(expectedScore, actualScore, 10e-5); matched.set(true); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java index 7b5fba63fbb..88564314fab 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java @@ -183,7 +183,7 @@ public class TestDocValuesScoring extends LuceneTestCase { Explanation boostExplanation = Explanation.match(getValueForDoc(doc), "indexDocValue(" + boostField + ")"); Explanation simExplanation = sub.explain(doc, freq); return Explanation.match( - boostExplanation.getValue() * simExplanation.getValue(), + boostExplanation.getValue().doubleValue() * simExplanation.getValue().doubleValue(), "product of:", boostExplanation, simExplanation); } }; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java index 9f5de37636c..d4aa9cfe018 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java @@ -257,7 +257,7 @@ public class TestQueryRescorer extends LuceneTestCase { assertTrue(s.contains("combined first and second pass score")); assertTrue(s.contains("first pass score")); assertTrue(s.contains("= second pass score")); - assertEquals(hits2.scoreDocs[0].score, explain.getValue(), 0.0f); + assertEquals(hits2.scoreDocs[0].score, explain.getValue().doubleValue(), 0.0f); docID = hits2.scoreDocs[1].doc; explain = rescorer.explain(searcher, @@ -269,7 +269,7 @@ public class TestQueryRescorer extends LuceneTestCase { assertTrue(s.contains("first pass score")); assertTrue(s.contains("no second pass score")); assertFalse(s.contains("= second pass score")); - assertEquals(hits2.scoreDocs[1].score, explain.getValue(), 0.0f); + assertEquals(hits2.scoreDocs[1].score, explain.getValue().doubleValue(), 0.0f); r.close(); dir.close(); diff --git a/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarity2.java b/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarity2.java index 49dc154a744..2f0b5fe1fa8 100644 --- a/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarity2.java +++ b/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarity2.java @@ -208,7 +208,7 @@ public class TestSimilarity2 extends LuceneTestCase { is.setSimilarity(sims.get(i)); Explanation expected = scores.get(i); Explanation actual = is.explain(query, 0); - assertEquals(sims.get(i).toString() + ": actual=" + actual + ",expected=" + expected, expected.getValue(), actual.getValue(), 0F); + assertEquals(sims.get(i).toString() + ": actual=" + actual + ",expected=" + expected, expected.getValue(), actual.getValue()); } iw.close(); diff --git a/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java b/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java index be85801a471..279e30ccc0b 100644 --- a/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java +++ b/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java @@ -213,7 +213,7 @@ public class TestSimilarityBase extends LuceneTestCase { toTermStats(stats)); float score = (float)sim.score(realStats, freq, docLen); float explScore = sim.explain( - realStats, 1, Explanation.match(freq, "freq"), docLen).getValue(); + realStats, 1, Explanation.match(freq, "freq"), docLen).getValue().floatValue(); assertFalse("Score infinite: " + sim.toString(), Float.isInfinite(score)); assertFalse("Score NaN: " + sim.toString(), Float.isNaN(score)); assertTrue("Score negative: " + sim.toString(), score >= 0); diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java index 1941baebbb1..3cf8ebde0ec 100644 --- a/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java +++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java @@ -148,8 +148,8 @@ public class TestBasics extends LuceneTestCase { checkHits(query, new int[] {77, 177, 277, 377, 477, 577, 677, 777, 877, 977, 1077, 1177, 1277, 1377, 1477, 1577, 1677, 1777, 1877, 1977}); - assertTrue(searcher.explain(query, 77).getValue() > 0.0f); - assertTrue(searcher.explain(query, 977).getValue() > 0.0f); + assertTrue(searcher.explain(query, 77).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 977).getValue().doubleValue() > 0.0f); } public void testSpanTermQuery() throws Exception { @@ -193,8 +193,8 @@ public class TestBasics extends LuceneTestCase { checkHits(query, new int[] {801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891}); - assertTrue(searcher.explain(query, 801).getValue() > 0.0f); - assertTrue(searcher.explain(query, 891).getValue() > 0.0f); + assertTrue(searcher.explain(query, 801).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 891).getValue().doubleValue() > 0.0f); } public void testSpanNotNoOverflowOnLargeSpans() throws Exception { @@ -214,8 +214,8 @@ public class TestBasics extends LuceneTestCase { {801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891}); - assertTrue(searcher.explain(query, 801).getValue() > 0.0f); - assertTrue(searcher.explain(query, 891).getValue() > 0.0f); + assertTrue(searcher.explain(query, 801).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 891).getValue().doubleValue() > 0.0f); } public void testSpanWithMultipleNotMany() throws Exception { @@ -226,8 +226,8 @@ public class TestBasics extends LuceneTestCase { checkHits(query, new int[] {801, 821, 831, 851, 871, 891, 1801, 1821, 1831, 1851, 1871, 1891}); - assertTrue(searcher.explain(query, 801).getValue() > 0.0f); - assertTrue(searcher.explain(query, 891).getValue() > 0.0f); + assertTrue(searcher.explain(query, 801).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 891).getValue().doubleValue() > 0.0f); } public void testNpeInSpanNearWithSpanNot() throws Exception { @@ -239,8 +239,8 @@ public class TestBasics extends LuceneTestCase { {801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891}); - assertTrue(searcher.explain(query, 801).getValue() > 0.0f); - assertTrue(searcher.explain(query, 891).getValue() > 0.0f); + assertTrue(searcher.explain(query, 801).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 891).getValue().doubleValue() > 0.0f); } public void testNpeInSpanNearInSpanFirstInSpanNot() throws Exception { @@ -267,8 +267,8 @@ public class TestBasics extends LuceneTestCase { {840, 842, 843, 844, 845, 846, 847, 848, 849, 1840, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849}); - assertTrue(searcher.explain(query, 840).getValue() > 0.0f); - assertTrue(searcher.explain(query, 1842).getValue() > 0.0f); + assertTrue(searcher.explain(query, 840).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 1842).getValue().doubleValue() > 0.0f); } public void testSpanNotWindowTwoBefore() throws Exception { @@ -278,8 +278,8 @@ public class TestBasics extends LuceneTestCase { checkHits(query, new int[] {840, 841, 842, 843, 844, 845, 846, 847, 848, 849}); - assertTrue(searcher.explain(query, 840).getValue() > 0.0f); - assertTrue(searcher.explain(query, 849).getValue() > 0.0f); + assertTrue(searcher.explain(query, 840).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 849).getValue().doubleValue() > 0.0f); } public void testSpanNotWindowNegPost() throws Exception { @@ -296,8 +296,8 @@ public class TestBasics extends LuceneTestCase { {801, 821, 831, 841, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1841, 1851, 1861, 1871, 1881, 1891}); - assertTrue(searcher.explain(query, 801).getValue() > 0.0f); - assertTrue(searcher.explain(query, 891).getValue() > 0.0f); + assertTrue(searcher.explain(query, 801).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 891).getValue().doubleValue() > 0.0f); } public void testSpanNotWindowNegPre() throws Exception { @@ -314,8 +314,8 @@ public class TestBasics extends LuceneTestCase { {801, 821, 831, 841, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1841, 1851, 1861, 1871, 1881, 1891}); - assertTrue(searcher.explain(query, 801).getValue() > 0.0f); - assertTrue(searcher.explain(query, 891).getValue() > 0.0f); + assertTrue(searcher.explain(query, 801).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 891).getValue().doubleValue() > 0.0f); } public void testSpanNotWindowDoubleExcludesBefore() throws Exception { @@ -327,8 +327,8 @@ public class TestBasics extends LuceneTestCase { checkHits(query, new int[] {42, 242, 342, 442, 542, 642, 742, 842, 942}); - assertTrue(searcher.explain(query, 242).getValue() > 0.0f); - assertTrue(searcher.explain(query, 942).getValue() > 0.0f); + assertTrue(searcher.explain(query, 242).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 942).getValue().doubleValue() > 0.0f); } public void testSpanFirst() throws Exception { @@ -344,8 +344,8 @@ public class TestBasics extends LuceneTestCase { 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599}); - assertTrue(searcher.explain(query, 5).getValue() > 0.0f); - assertTrue(searcher.explain(query, 599).getValue() > 0.0f); + assertTrue(searcher.explain(query, 5).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 599).getValue().doubleValue() > 0.0f); } @@ -355,8 +355,8 @@ public class TestBasics extends LuceneTestCase { checkHits(query, new int[] {25,35, 45, 55, 65, 75, 85, 95}); - assertTrue(searcher.explain(query, 25).getValue() > 0.0f); - assertTrue(searcher.explain(query, 95).getValue() > 0.0f); + assertTrue(searcher.explain(query, 25).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 95).getValue().doubleValue() > 0.0f); query = spanPositionRangeQuery(term1, 0, 1); checkHits(query, new int[] @@ -384,8 +384,8 @@ public class TestBasics extends LuceneTestCase { 747, 833, 847, 933, 947, 1033, 1047, 1133, 1147, 1233, 1247, 1333, 1347, 1433, 1447, 1533, 1547, 1633, 1647, 1733, 1747, 1833, 1847, 1933, 1947}); - assertTrue(searcher.explain(query, 33).getValue() > 0.0f); - assertTrue(searcher.explain(query, 947).getValue() > 0.0f); + assertTrue(searcher.explain(query, 33).getValue().doubleValue() > 0.0f); + assertTrue(searcher.explain(query, 947).getValue().doubleValue() > 0.0f); } public void testSpanExactNested() throws Exception { @@ -395,7 +395,7 @@ public class TestBasics extends LuceneTestCase { checkHits(query, new int[] {333, 1333}); - assertTrue(searcher.explain(query, 333).getValue() > 0.0f); + assertTrue(searcher.explain(query, 333).getValue().doubleValue() > 0.0f); } public void testSpanNearOr() throws Exception { diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java index 348b1e7f332..072d3818490 100644 --- a/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java +++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java @@ -255,7 +255,7 @@ public class TestNearSpansOrdered extends LuceneTestCase { Explanation e = searcher.explain(q, 1); assertTrue("Scorer explanation value for doc#1 isn't positive: " + e.toString(), - 0.0f <= e.getValue()); + 0.0f <= e.getValue().doubleValue()); } public void testGaps() throws Exception { diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java index 2bfafabc183..8cec5cc1533 100644 --- a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java +++ b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java @@ -158,7 +158,7 @@ final class ExpressionValueSource extends DoubleValuesSource { @Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { Explanation[] explanations = new Explanation[variables.length]; - DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue()).getValues(ctx, null)); + DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue().doubleValue()).getValues(ctx, null)); if (dv.advanceExact(docId) == false) { return Explanation.noMatch(expression.sourceText); } @@ -166,7 +166,7 @@ final class ExpressionValueSource extends DoubleValuesSource { for (DoubleValuesSource var : variables) { explanations[i++] = var.explain(ctx, docId, scoreExplanation); } - return Explanation.match((float) dv.doubleValue(), expression.sourceText + ", computed from:", explanations); + return Explanation.match(dv.doubleValue(), expression.sourceText + ", computed from:", explanations); } @Override diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java index 1e371684cb2..6b4acff9332 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java @@ -347,7 +347,7 @@ public class ToParentBlockJoinQuery extends Query { Explanation child = childWeight.explain(context, childDoc - context.docBase); if (child.isMatch()) { matches++; - if (bestChild == null || child.getValue() > bestChild.getValue()) { + if (bestChild == null || child.getValue().floatValue() > bestChild.getValue().floatValue()) { bestChild = child; } } diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java index bd7966eab02..d70beaf2929 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java @@ -833,7 +833,7 @@ public class TestBlockJoin extends LuceneTestCase { int childId = Integer.parseInt(document.get("childID")); //System.out.println(" hit docID=" + hit.doc + " childId=" + childId + " parentId=" + document.get("parentID")); assertTrue(explanation.isMatch()); - assertEquals(hit.score, explanation.getValue(), 0.0f); + assertEquals(hit.score, explanation.getValue().doubleValue(), 0.0f); Matcher m = Pattern.compile("Score based on ([0-9]+) child docs in range from ([0-9]+) to ([0-9]+), best match:").matcher(explanation.getDescription()); assertTrue("Block Join description not matches", m.matches()); assertTrue("Matched children not positive", Integer.parseInt(m.group(1)) > 0); @@ -1373,7 +1373,7 @@ public class TestBlockJoin extends LuceneTestCase { TopDocs hits = s.search(toChildQuery, 10); assertEquals(hits.scoreDocs.length, 2); for (int i = 0; i < hits.scoreDocs.length; i++) { - assertEquals(hits.scoreDocs[i].score, s.explain(toChildQuery, hits.scoreDocs[i].doc).getValue(), 0.01); + assertEquals(hits.scoreDocs[i].score, s.explain(toChildQuery, hits.scoreDocs[i].doc).getValue().doubleValue(), 0f); } r.close(); diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java index 3184150e29a..088bb87b7cd 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java @@ -1293,7 +1293,7 @@ public class TestJoinUtil extends LuceneTestCase { assertEquals(expectedTopDocs.scoreDocs[i].doc, actualTopDocs.scoreDocs[i].doc); assertEquals(expectedTopDocs.scoreDocs[i].score, actualTopDocs.scoreDocs[i].score, 0.0f); Explanation explanation = indexSearcher.explain(joinQuery, expectedTopDocs.scoreDocs[i].doc); - assertEquals(expectedTopDocs.scoreDocs[i].score, explanation.getValue(), 0.0f); + assertEquals(expectedTopDocs.scoreDocs[i].score, explanation.getValue().doubleValue(), 0.0f); } } diff --git a/lucene/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java b/lucene/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java index a2b324e6d6e..6ad94911e8d 100644 --- a/lucene/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java +++ b/lucene/misc/src/test/org/apache/lucene/misc/SweetSpotSimilarityTest.java @@ -55,7 +55,7 @@ public class SweetSpotSimilarityTest extends LuceneTestCase { dir.close(); Explanation norm = findExplanation(expl, "fieldNorm"); assertNotNull(norm); - return norm.getValue(); + return norm.getValue().floatValue(); } private static Explanation findExplanation(Explanation expl, String text) { diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java index 3ae08fd35bf..da41246b1f6 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java @@ -131,13 +131,13 @@ public class FunctionQuery extends Query { public Explanation explain(int doc) throws IOException { Explanation expl = vals.explain(doc); - if (expl.getValue() < 0) { + if (expl.getValue().floatValue() < 0) { expl = Explanation.match(0, "truncated score, max of:", Explanation.match(0f, "minimum score"), expl); - } else if (Float.isNaN(expl.getValue())) { + } else if (Float.isNaN(expl.getValue().floatValue())) { expl = Explanation.match(0, "score, computed as (score == NaN ? 0 : score) since NaN is an illegal score from:", expl); } - return Explanation.match(boost * expl.getValue(), "FunctionQuery(" + func + "), product of:", + return Explanation.match(boost * expl.getValue().floatValue(), "FunctionQuery(" + func + "), product of:", vals.explain(doc), Explanation.match(weight.boost, "boost")); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java index 61cf973da54..4b8111e818e 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java @@ -249,7 +249,7 @@ public abstract class ValueSource { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { Map context = new HashMap<>(); FakeScorer scorer = new FakeScorer(); - scorer.score = scoreExplanation.getValue(); + scorer.score = scoreExplanation.getValue().floatValue(); context.put("scorer", scorer); context.put("searcher", searcher); FunctionValues fv = in.getValues(context, ctx); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java index 2e705892e1e..6704ba1525b 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java @@ -244,9 +244,9 @@ public class PayloadScoreQuery extends SpanQuery { protected Explanation getPayloadExplanation() { Explanation expl = function.explain(docID(), getField(), spans.payloadsSeen, spans.payloadScore); - if (expl.getValue() < 0) { + if (expl.getValue().floatValue() < 0) { expl = Explanation.match(0, "truncated score, max of:", Explanation.match(0f, "minimum score"), expl); - } else if (Float.isNaN(expl.getValue())) { + } else if (Float.isNaN(expl.getValue().floatValue())) { expl = Explanation.match(0, "payload score, computed as (score == NaN ? 0 : score) since NaN is an illegal score from:", expl); } return expl; diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreExplanations.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreExplanations.java index 8df417dfb7a..456fb9e088b 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreExplanations.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreExplanations.java @@ -67,7 +67,7 @@ public class TestFunctionScoreExplanations extends BaseExplanationTestCase { Explanation e1 = searcher.explain(q, 0); Explanation e = searcher.explain(fsq, 0); - assertEquals(e.getValue(), e1.getValue(), 0.00001); + assertEquals(e.getValue(), e1.getValue()); assertEquals(e.getDetails()[0], e1); } @@ -86,19 +86,19 @@ public class TestFunctionScoreExplanations extends BaseExplanationTestCase { expl = searcher.explain(query, 0); assertEquals(2, expl.getDetails().length); // function - assertEquals(5f, expl.getDetails()[1].getValue(), 0f); + assertEquals(5f, expl.getDetails()[1].getValue().doubleValue(), 0f); // boost assertEquals("boost", expl.getDetails()[0].getDescription()); - assertEquals(2f, expl.getDetails()[0].getValue(), 0f); + assertEquals(2f, expl.getDetails()[0].getValue().doubleValue(), 0f); searcher.setSimilarity(new ClassicSimilarity()); // in order to have a queryNorm != 1 expl = searcher.explain(query, 0); assertEquals(2, expl.getDetails().length); // function - assertEquals(5f, expl.getDetails()[1].getValue(), 0f); + assertEquals(5f, expl.getDetails()[1].getValue().doubleValue(), 0f); // boost assertEquals("boost", expl.getDetails()[0].getDescription()); - assertEquals(2f, expl.getDetails()[0].getValue(), 0f); + assertEquals(2f, expl.getDetails()[0].getValue().doubleValue(), 0f); } } diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java index 301dce7334b..c0560bc0313 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java @@ -161,7 +161,7 @@ public class TestFunctionScoreQuery extends FunctionTestSetup { Query q = new FunctionScoreQuery(new MatchAllDocsQuery(), DoubleValuesSource.fromLongField("foo")); QueryUtils.check(random(), q, searcher); Explanation expl = searcher.explain(q, 0); - assertEquals(0, expl.getValue(), 0f); + assertEquals(0, expl.getValue().doubleValue(), 0f); assertTrue(expl.toString(), expl.getDetails()[0].getDescription().contains("truncated score")); reader.close(); dir.close(); @@ -179,7 +179,7 @@ public class TestFunctionScoreQuery extends FunctionTestSetup { Query q = new FunctionScoreQuery(new MatchAllDocsQuery(), DoubleValuesSource.fromDoubleField("foo")); QueryUtils.check(random(), q, searcher); Explanation expl = searcher.explain(q, 0); - assertEquals(0, expl.getValue(), 0f); + assertEquals(0, expl.getValue().doubleValue(), 0f); assertTrue(expl.toString(), expl.getDetails()[0].getDescription().contains("NaN is an illegal score")); reader.close(); dir.close(); diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java index 9e347841479..68691772593 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadCheckQuery.java @@ -98,7 +98,7 @@ public class TestPayloadCheckQuery extends LuceneTestCase { SpanQuery query = new SpanPayloadCheckQuery(term1, Collections.singletonList(pay)); checkHits(query, new int[] {1125, 1135, 1145, 1155, 1165, 1175, 1185, 1195, 1225, 1235, 1245, 1255, 1265, 1275, 1285, 1295, 1325, 1335, 1345, 1355, 1365, 1375, 1385, 1395, 1425, 1435, 1445, 1455, 1465, 1475, 1485, 1495, 1525, 1535, 1545, 1555, 1565, 1575, 1585, 1595, 1625, 1635, 1645, 1655, 1665, 1675, 1685, 1695, 1725, 1735, 1745, 1755, 1765, 1775, 1785, 1795, 1825, 1835, 1845, 1855, 1865, 1875, 1885, 1895, 1925, 1935, 1945, 1955, 1965, 1975, 1985, 1995}); - assertTrue(searcher.explain(query, 1125).getValue() > 0.0f); + assertTrue(searcher.explain(query, 1125).getValue().doubleValue() > 0.0f); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "hundred")); SpanNearQuery snq; diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/CoveringQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/CoveringQuery.java index 0371f2fe03b..8f821922c6d 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/search/CoveringQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/search/CoveringQuery.java @@ -150,7 +150,7 @@ public final class CoveringQuery extends Query { Explanation subExpl = weight.explain(context, doc); if (subExpl.isMatch()) { freq++; - score += subExpl.getValue(); + score += subExpl.getValue().doubleValue(); } subExpls.add(subExpl); } diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java index e536f667675..d6597c67224 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java @@ -104,7 +104,7 @@ public abstract class BBoxSimilarityValueSource extends DoubleValuesSource { @Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { - DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue()).getValues(ctx, null)); + DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue().doubleValue()).getValues(ctx, null)); if (dv.advanceExact(docId)) { AtomicReference explanation = new AtomicReference<>(); final ShapeValues shapeValues = bboxValueSource.getValues(ctx); diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ReciprocalDoubleValuesSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ReciprocalDoubleValuesSource.java index df1f5716251..4475a42ae32 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ReciprocalDoubleValuesSource.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ReciprocalDoubleValuesSource.java @@ -77,7 +77,7 @@ public class ReciprocalDoubleValuesSource extends DoubleValuesSource { @Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { Explanation expl = input.explain(ctx, docId, scoreExplanation); - return Explanation.match((float)recip(expl.getValue()), + return Explanation.match(recip(expl.getValue().doubleValue()), distToEdge + " / (v + " + distToEdge + "), computed from:", expl); } diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/CheckHits.java b/lucene/test-framework/src/java/org/apache/lucene/search/CheckHits.java index 2797427bad8..9c8943d8044 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/CheckHits.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/CheckHits.java @@ -316,7 +316,7 @@ public class CheckHits { float score, boolean deep, Explanation expl) { - float value = expl.getValue(); + float value = expl.getValue().floatValue(); // TODO: clean this up if we use junit 5 (the assert message is costly) try { Assert.assertEquals(score, value, 0d); @@ -382,7 +382,7 @@ public class CheckHits { float max = Float.NEGATIVE_INFINITY; double maxError = 0; for (int i=0; i maxScore: " + score + " > " + maxScore, score <= maxScore); // check explanation matches Explanation explanation = scorer.explain(0, Explanation.match(freq, "freq, occurrences of term within document")); - if (score != explanation.getValue()) { + if (score != explanation.getValue().doubleValue()) { fail("expected: " + score + ", got: " + explanation); } CheckHits.verifyExplanation("", 0, score, true, explanation); @@ -473,7 +473,7 @@ public abstract class BaseSimilarityTestCase extends LuceneTestCase { assertTrue(prevScore >= 0); // check explanation matches Explanation prevExplanation = scorer.explain(0, Explanation.match(prevFreq, "freq, occurrences of term within document")); - if (prevScore != prevExplanation.getValue()) { + if (prevScore != prevExplanation.getValue().doubleValue()) { fail("expected: " + prevScore + ", got: " + prevExplanation); } CheckHits.verifyExplanation("test query (prevFreq)", 0, prevScore, true, prevExplanation); @@ -493,7 +493,7 @@ public abstract class BaseSimilarityTestCase extends LuceneTestCase { assertTrue(prevNormScore >= 0); // check explanation matches Explanation prevNormExplanation = prevNormScorer.explain(0, Explanation.match(freq, "freq, occurrences of term within document")); - if (prevNormScore != prevNormExplanation.getValue()) { + if (prevNormScore != prevNormExplanation.getValue().doubleValue()) { fail("expected: " + prevNormScore + ", got: " + prevNormExplanation); } CheckHits.verifyExplanation("test query (prevNorm)", 0, prevNormScore, true, prevNormExplanation); @@ -516,7 +516,7 @@ public abstract class BaseSimilarityTestCase extends LuceneTestCase { assertTrue(prevTermScore >= 0); // check explanation matches Explanation prevTermExplanation = prevTermScorer.explain(0, Explanation.match(freq, "freq, occurrences of term within document")); - if (prevTermScore != prevTermExplanation.getValue()) { + if (prevTermScore != prevTermExplanation.getValue().doubleValue()) { fail("expected: " + prevTermScore + ", got: " + prevTermExplanation); } CheckHits.verifyExplanation("test query (prevTerm)", 0, prevTermScore, true, prevTermExplanation); diff --git a/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java b/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java index 8e5db287223..2f0f067c513 100644 --- a/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java +++ b/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java @@ -89,7 +89,7 @@ public class TestBaseExplanationTestCase extends BaseExplanationTestCase { Explanation result = in.explain(context, doc); if (result.isMatch()) { if (q.breakExplainScores) { - result = Explanation.match(-1F * result.getValue(), "Broken Explanation Score", result); + result = Explanation.match(-1F * result.getValue().doubleValue(), "Broken Explanation Score", result); } if (q.toggleExplainMatch) { result = Explanation.noMatch("Broken Explanation Matching", result); diff --git a/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/LinearModel.java b/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/LinearModel.java index ee065c36249..08780ca9bb8 100644 --- a/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/LinearModel.java +++ b/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/LinearModel.java @@ -129,7 +129,7 @@ public class LinearModel extends LTRScoringModel { "weight on feature")); featureDetails.add(featureExplain); - details.add(Explanation.match(featureExplain.getValue() + details.add(Explanation.match(featureExplain.getValue().doubleValue() * featureToWeight[index], "prod of:", featureDetails)); index++; } diff --git a/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/MultipleAdditiveTreesModel.java b/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/MultipleAdditiveTreesModel.java index 278a4f56889..23d4886a62b 100644 --- a/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/MultipleAdditiveTreesModel.java +++ b/solr/contrib/ltr/src/java/org/apache/solr/ltr/model/MultipleAdditiveTreesModel.java @@ -345,7 +345,7 @@ public class MultipleAdditiveTreesModel extends LTRScoringModel { final float[] fv = new float[featureExplanations.size()]; int index = 0; for (final Explanation featureExplain : featureExplanations) { - fv[index] = featureExplain.getValue(); + fv[index] = featureExplain.getValue().floatValue(); index++; } diff --git a/solr/contrib/ltr/src/java/org/apache/solr/ltr/norm/Normalizer.java b/solr/contrib/ltr/src/java/org/apache/solr/ltr/norm/Normalizer.java index 2b311f8cc7b..b4751732b6d 100644 --- a/solr/contrib/ltr/src/java/org/apache/solr/ltr/norm/Normalizer.java +++ b/solr/contrib/ltr/src/java/org/apache/solr/ltr/norm/Normalizer.java @@ -36,7 +36,7 @@ public abstract class Normalizer { public abstract LinkedHashMap paramsToMap(); public Explanation explain(Explanation explain) { - final float normalized = normalize(explain.getValue()); + final float normalized = normalize(explain.getValue().floatValue()); final String explainDesc = "normalized using " + toString(); return Explanation.match(normalized, explainDesc, explain); diff --git a/solr/core/src/java/org/apache/solr/schema/LatLonType.java b/solr/core/src/java/org/apache/solr/schema/LatLonType.java index 31679fb3263..8cf86b8fff8 100644 --- a/solr/core/src/java/org/apache/solr/schema/LatLonType.java +++ b/solr/core/src/java/org/apache/solr/schema/LatLonType.java @@ -497,7 +497,7 @@ class SpatialDistanceQuery extends ExtendedQueryBase implements PostFilter { double dist = dist(latVals.doubleVal(doc), lonVals.doubleVal(doc)); String description = SpatialDistanceQuery.this.toString(); - return Explanation.match((float) (base.getValue() * dist), description + " product of:", + return Explanation.match((float) (base.getValue().floatValue() * dist), description + " product of:", base, Explanation.match((float) dist, "hsin("+latVals.doubleVal(doc)+","+lonVals.doubleVal(doc))); } diff --git a/solr/core/src/test/org/apache/solr/search/similarities/TestSweetSpotSimilarityFactory.java b/solr/core/src/test/org/apache/solr/search/similarities/TestSweetSpotSimilarityFactory.java index 52d6f8d4c04..c6f4ac3048a 100644 --- a/solr/core/src/test/org/apache/solr/search/similarities/TestSweetSpotSimilarityFactory.java +++ b/solr/core/src/test/org/apache/solr/search/similarities/TestSweetSpotSimilarityFactory.java @@ -57,7 +57,7 @@ public class TestSweetSpotSimilarityFactory extends BaseSimilarityTestCase { dir.close(); Explanation norm = findExplanation(expl, "fieldNorm"); assertNotNull(norm); - return norm.getValue(); + return norm.getValue().floatValue(); } private static Explanation findExplanation(Explanation expl, String text) {