mirror of https://github.com/apache/lucene.git
SOLR-1485: fix tests, removing unnecessary tie to Similarity in PayloadDecoder
This commit is contained in:
parent
6c565c001b
commit
a68b778e5d
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue