diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index d31afe98141..13a5e1f4b3a 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -58,6 +58,10 @@ Bug fixes matching. This behaviour can be disabled if users are more interested in speed rather than accuracy of matching. (Alan Woodward, Jim Ferenczi) +* LUCENE-8741: ValueSource.fromDoubleValuesSource() was casting to + Scorer instead of Scorable, leading to ClassCastExceptions (Markus Jelsma, + Alan Woodward) + Improvements * LUCENE-8673: Use radix partitioning when merging dimensional points instead 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 0cbfe89a46d..1ba35804002 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 @@ -32,7 +32,6 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.LongValues; import org.apache.lucene.search.LongValuesSource; import org.apache.lucene.search.Scorable; -import org.apache.lucene.search.Scorer; import org.apache.lucene.search.SimpleFieldComparator; import org.apache.lucene.search.SortField; @@ -285,7 +284,7 @@ public abstract class ValueSource { @Override public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { - Scorer scorer = (Scorer) context.get("scorer"); + Scorable scorer = (Scorable) context.get("scorer"); DoubleValues scores = scorer == null ? null : DoubleValuesSource.fromScorer(scorer); IndexSearcher searcher = (IndexSearcher) context.get("searcher"); diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java index 0b84c93f2b5..ba0e4703490 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java @@ -38,6 +38,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.queries.function.docvalues.FloatDocValues; import org.apache.lucene.queries.function.valuesource.*; import org.apache.lucene.search.CheckHits; +import org.apache.lucene.search.DoubleValuesSource; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; @@ -580,6 +581,11 @@ public class TestValueSources extends LuceneTestCase { assertNull(source2.searcher); } + + public void testBuildingFromDoubleValues() throws Exception { + DoubleValuesSource dvs = ValueSource.fromDoubleValuesSource(DoubleValuesSource.fromDoubleField("double")).asDoubleValuesSource(); + assertHits(new FunctionQuery(ValueSource.fromDoubleValuesSource(dvs)), new float[] { 3.63f, 5.65f }); + } /** * Asserts that for every doc, the {@link FunctionValues#exists} value