diff --git a/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java b/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java index e926ef8dcb0..65b5fa01354 100644 --- a/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java +++ b/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java @@ -163,7 +163,7 @@ public class FloatPayloadValueSource extends ValueSource { docs.nextPosition(); BytesRef payload = docs.getPayload(); if (payload != null) { - float payloadVal = decoder.decode(null, atDoc, docs.startOffset(), docs.endOffset(), payload); + float payloadVal = decoder.decode(atDoc, docs.startOffset(), docs.endOffset(), payload); // payloadFunction = null represents "first" if (payloadFunction == null) return payloadVal; diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java index 6032e0d5629..b5116560e68 100644 --- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java +++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java @@ -739,6 +739,11 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin { FieldType fieldType = fp.getReq().getCore().getLatestSchema().getFieldTypeNoEx(tinfo.field); PayloadDecoder decoder = PayloadUtils.getPayloadDecoder(fieldType); + + if (decoder==null) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No payload decoder found for field: " + tinfo.field); + } + return new FloatPayloadValueSource( tinfo.field, tinfo.val, diff --git a/solr/core/src/java/org/apache/solr/search/similarities/PayloadScoringSimilarityWrapper.java b/solr/core/src/java/org/apache/solr/search/similarities/PayloadScoringSimilarityWrapper.java index 4a86c42a7cb..9141620f969 100644 --- a/solr/core/src/java/org/apache/solr/search/similarities/PayloadScoringSimilarityWrapper.java +++ b/solr/core/src/java/org/apache/solr/search/similarities/PayloadScoringSimilarityWrapper.java @@ -71,7 +71,7 @@ public class PayloadScoringSimilarityWrapper extends Similarity { @Override public float computePayloadFactor(int doc, int start, int end, BytesRef payload) { - return decoder.decode(simScorer, doc, start, end, payload); + return decoder.decode(doc, start, end, payload); } }; diff --git a/solr/core/src/java/org/apache/solr/util/PayloadDecoder.java b/solr/core/src/java/org/apache/solr/util/PayloadDecoder.java index f9495b102fc..cca50e2c3f9 100644 --- a/solr/core/src/java/org/apache/solr/util/PayloadDecoder.java +++ b/solr/core/src/java/org/apache/solr/util/PayloadDecoder.java @@ -24,5 +24,5 @@ import org.apache.lucene.util.BytesRef; * Mirrors SimScorer#computePayloadFactor's signature */ public interface PayloadDecoder { - float decode(Similarity.SimScorer simScorer, int doc, int start, int end, BytesRef payload); + float decode(int doc, int start, int end, BytesRef payload); } diff --git a/solr/core/src/java/org/apache/solr/util/PayloadUtils.java b/solr/core/src/java/org/apache/solr/util/PayloadUtils.java index 79275945da0..32e2fd95240 100644 --- a/solr/core/src/java/org/apache/solr/util/PayloadUtils.java +++ b/solr/core/src/java/org/apache/solr/util/PayloadUtils.java @@ -33,7 +33,6 @@ import org.apache.lucene.queries.payloads.AveragePayloadFunction; import org.apache.lucene.queries.payloads.MaxPayloadFunction; import org.apache.lucene.queries.payloads.MinPayloadFunction; import org.apache.lucene.queries.payloads.PayloadFunction; -import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.search.spans.SpanNearQuery; import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.search.spans.SpanTermQuery; @@ -69,15 +68,15 @@ public class PayloadUtils { } public static PayloadDecoder getPayloadDecoder(FieldType fieldType) { - PayloadDecoder decoder = Similarity.SimScorer::computePayloadFactor; // default to SimScorer's + PayloadDecoder decoder = null; String encoder = getPayloadEncoder(fieldType); if ("integer".equals(encoder)) { - decoder = (Similarity.SimScorer simScorer, int doc, int start, int end, BytesRef payload) -> PayloadHelper.decodeInt(payload.bytes, payload.offset); + decoder = (int doc, int start, int end, BytesRef payload) -> PayloadHelper.decodeInt(payload.bytes, payload.offset); } if ("float".equals(encoder)) { - decoder = (Similarity.SimScorer simScorer, int doc, int start, int end, BytesRef payload) -> PayloadHelper.decodeFloat(payload.bytes, payload.offset); + decoder = (int doc, int start, int end, BytesRef payload) -> PayloadHelper.decodeFloat(payload.bytes, payload.offset); } // encoder could be "identity" at this point, in the case of DelimitedTokenFilterFactory encoder="identity" diff --git a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java index f218bd902e2..8aae74c56d0 100644 --- a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java +++ b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java @@ -465,28 +465,29 @@ public class TestFunctionQuery extends SolrTestCaseJ4 { public void testPayloadFunction() { clearIndex(); - assertU(adoc("id","1", "vals_dp","A|1.0 B|2.0 C|3.0 mult|50 mult|100 x|22 x|37 x|19", "default_f", "42.0")); + assertU(adoc("id","1", "vals_dpf","A|1.0 B|2.0 C|3.0 mult|50 mult|100 x|22 x|37 x|19", "default_f", "42.0")); assertU(commit()); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,A)"), "//float[@name='score']='1.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,B)"), "//float[@name='score']='2.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,C,0)"), "//float[@name='score']='3.0'"); + + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,A)"), "//float[@name='score']='1.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,B)"), "//float[@name='score']='2.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,C,0)"), "//float[@name='score']='3.0'"); // Test defaults, constant, field, and function value sources - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,D,37.0)"), "//float[@name='score']='37.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,E,default_f)"), "//float[@name='score']='42.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,E,mul(2,default_f))"), "//float[@name='score']='84.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,D,37.0)"), "//float[@name='score']='37.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,E,default_f)"), "//float[@name='score']='42.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,E,mul(2,default_f))"), "//float[@name='score']='84.0'"); // Test PayloadFunction's for multiple terms, average being the default - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,mult,0.0,min)"), "//float[@name='score']='50.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,mult,0.0,max)"), "//float[@name='score']='100.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,mult,0.0,average)"), "//float[@name='score']='75.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,mult)"), "//float[@name='score']='75.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,mult,0.0,min)"), "//float[@name='score']='50.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,mult,0.0,max)"), "//float[@name='score']='100.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,mult,0.0,average)"), "//float[@name='score']='75.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,mult)"), "//float[@name='score']='75.0'"); // Test special "first" function, by checking the other functions with same term too - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,x,0.0,min)"), "//float[@name='score']='19.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,x,0.0,max)"), "//float[@name='score']='37.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,x,0.0,average)"), "//float[@name='score']='26.0'"); - assertQ(req("fl","*,score","q", "{!func}payload(vals_dp,x,0.0,first)"), "//float[@name='score']='22.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,x,0.0,min)"), "//float[@name='score']='19.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,x,0.0,max)"), "//float[@name='score']='37.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,x,0.0,average)"), "//float[@name='score']='26.0'"); + assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,x,0.0,first)"), "//float[@name='score']='22.0'"); } @Test