LUCENE-4250: fix trap in PayloadFunction explain API

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1365837 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-07-25 23:23:02 +00:00
parent 645547df3e
commit 436175cfaf
7 changed files with 12 additions and 32 deletions

View File

@ -63,6 +63,10 @@ API Changes
at all. If you want to tweak things like positionIncrementGap and offsetGap,
analyze the field with KeywordTokenizer instead. (Grant Ingersoll, Robert Muir)
* LUCENE-4250: Pass fieldName to the PayloadFunction explain method, so it
parallels with docScore and the default implementation is correct.
(Robert Muir)
Optimizations
* LUCENE-4171: Performance improvements to Packed64.

View File

@ -1,6 +1,5 @@
package org.apache.lucene.search.payloads;
import org.apache.lucene.search.Explanation;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -36,14 +35,6 @@ public class AveragePayloadFunction extends PayloadFunction{
public float docScore(int docId, String field, int numPayloadsSeen, float payloadScore) {
return numPayloadsSeen > 0 ? (payloadScore / numPayloadsSeen) : 1;
}
@Override
public Explanation explain(int doc, int numPayloadsSeen, float payloadScore) {
Explanation payloadBoost = new Explanation();
float avgPayloadScore = (numPayloadsSeen > 0 ? (payloadScore / numPayloadsSeen) : 1);
payloadBoost.setValue(avgPayloadScore);
payloadBoost.setDescription("AveragePayloadFunction(...)");
return payloadBoost;
}
@Override
public int hashCode() {

View File

@ -1,6 +1,5 @@
package org.apache.lucene.search.payloads;
import org.apache.lucene.search.Explanation;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -40,14 +39,6 @@ public class MaxPayloadFunction extends PayloadFunction {
return numPayloadsSeen > 0 ? payloadScore : 1;
}
@Override
public Explanation explain(int doc, int numPayloadsSeen, float payloadScore) {
Explanation expl = new Explanation();
float maxPayloadScore = (numPayloadsSeen > 0 ? payloadScore : 1);
expl.setValue(maxPayloadScore);
expl.setDescription("MaxPayloadFunction(...)");
return expl;
}
@Override
public int hashCode() {
final int prime = 31;

View File

@ -1,6 +1,5 @@
package org.apache.lucene.search.payloads;
import org.apache.lucene.search.Explanation;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -38,14 +37,6 @@ public class MinPayloadFunction extends PayloadFunction {
return numPayloadsSeen > 0 ? payloadScore : 1;
}
@Override
public Explanation explain(int doc, int numPayloadsSeen, float payloadScore) {
Explanation expl = new Explanation();
float minPayloadScore = (numPayloadsSeen > 0 ? payloadScore : 1);
expl.setValue(minPayloadScore);
expl.setDescription("MinPayloadFunction(...)");
return expl;
}
@Override
public int hashCode() {
final int prime = 31;

View File

@ -55,10 +55,10 @@ public abstract class PayloadFunction {
*/
public abstract float docScore(int docId, String field, int numPayloadsSeen, float payloadScore);
public Explanation explain(int docId, int numPayloadsSeen, float payloadScore){
public Explanation explain(int docId, String field, int numPayloadsSeen, float payloadScore){
Explanation result = new Explanation();
result.setDescription("Unimpl Payload Function Explain");
result.setValue(1);
result.setDescription(getClass().getSimpleName() + ".docScore()");
result.setValue(docScore(docId, field, numPayloadsSeen, payloadScore));
return result;
};

View File

@ -167,8 +167,9 @@ public class PayloadNearQuery extends SpanNearQuery {
Explanation scoreExplanation = docScorer.explain(doc, new Explanation(freq, "phraseFreq=" + freq));
expl.addDetail(scoreExplanation);
expl.setValue(scoreExplanation.getValue());
String field = ((SpanQuery)getQuery()).getField();
// now the payloads part
Explanation payloadExpl = function.explain(doc, scorer.payloadsSeen, scorer.payloadScore);
Explanation payloadExpl = function.explain(doc, field, scorer.payloadsSeen, scorer.payloadScore);
// combined
ComplexExplanation result = new ComplexExplanation();
result.addDetail(expl);

View File

@ -28,6 +28,7 @@ import org.apache.lucene.search.ComplexExplanation;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.search.similarities.Similarity.SloppySimScorer;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.TermSpans;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.search.spans.SpanWeight;
@ -190,7 +191,8 @@ public class PayloadTermQuery extends SpanTermQuery {
// whether to load the payload or not
// GSI: I suppose we could toString the payload, but I don't think that
// would be a good idea
Explanation payloadExpl = function.explain(doc, scorer.payloadsSeen, scorer.payloadScore);
String field = ((SpanQuery)getQuery()).getField();
Explanation payloadExpl = function.explain(doc, field, scorer.payloadsSeen, scorer.payloadScore);
payloadExpl.setValue(scorer.getPayloadScore());
// combined
ComplexExplanation result = new ComplexExplanation();