LUCENE-3421: PayloadTermQuery's explain was wrong when includeSpanScore=false

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1166656 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-09-08 12:33:51 +00:00
parent e758a5e444
commit 619b68a018
3 changed files with 112 additions and 5 deletions

View File

@ -540,6 +540,9 @@ Bug fixes
* LUCENE-3412: SloppyPhraseScorer was returning non-deterministic results
for queries with many repeats (Doron Cohen)
* LUCENE-3421: PayloadTermQuery's explain was wrong when includeSpanScore=false.
(Edward Drapkin via Robert Muir)
======================= Lucene 3.4.0 =======================
Bug fixes

View File

@ -194,11 +194,17 @@ public class PayloadTermQuery extends SpanTermQuery {
payloadExpl.setValue(scorer.getPayloadScore());
// combined
ComplexExplanation result = new ComplexExplanation();
if (includeSpanScore) {
result.addDetail(expl);
result.addDetail(payloadExpl);
result.setValue(expl.getValue() * payloadExpl.getValue());
result.setDescription("btq, product of:");
result.setMatch(expl.getValue() == 0 ? Boolean.FALSE : Boolean.TRUE); // LUCENE-1303
} else {
result.addDetail(payloadExpl);
result.setValue(payloadExpl.getValue());
result.setDescription("btq(includeSpanScore=false), result of:");
}
result.setMatch(true); // LUCENE-1303
return result;
}
}

View File

@ -0,0 +1,98 @@
package org.apache.lucene.search.payloads;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.lucene.index.Term;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.DefaultSimilarityProvider;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.TestExplanations;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.util.BytesRef;
/**
* TestExplanations subclass focusing on payload queries
*/
public class TestPayloadExplanations extends TestExplanations {
private PayloadFunction functions[] = new PayloadFunction[] {
new AveragePayloadFunction(),
new MinPayloadFunction(),
new MaxPayloadFunction(),
};
@Override
public void setUp() throws Exception {
super.setUp();
searcher.setSimilarityProvider(new DefaultSimilarityProvider() {
@Override
public Similarity get(String field) {
return new DefaultSimilarity() {
@Override
public float scorePayload(int doc, int start, int end, BytesRef payload) {
return 1 + (payload.hashCode() % 10);
}
};
}
});
}
/** macro for payloadtermquery */
private SpanQuery pt(String s, PayloadFunction fn, boolean includeSpanScore) {
return new PayloadTermQuery(new Term(FIELD,s), fn, includeSpanScore);
}
/* simple PayloadTermQueries */
public void testPT1() throws Exception {
for (PayloadFunction fn : functions) {
qtest(pt("w1", fn, false), new int[] {0,1,2,3});
qtest(pt("w1", fn, true), new int[] {0,1,2,3});
}
}
public void testPT2() throws Exception {
for (PayloadFunction fn : functions) {
SpanQuery q = pt("w1", fn, false);
q.setBoost(1000);
qtest(q, new int[] {0,1,2,3});
q = pt("w1", fn, true);
q.setBoost(1000);
qtest(q, new int[] {0,1,2,3});
}
}
public void testPT4() throws Exception {
for (PayloadFunction fn : functions) {
qtest(pt("xx", fn, false), new int[] {2,3});
qtest(pt("xx", fn, true), new int[] {2,3});
}
}
public void testPT5() throws Exception {
for (PayloadFunction fn : functions) {
SpanQuery q = pt("xx", fn, false);
q.setBoost(1000);
qtest(q, new int[] {2,3});
q = pt("xx", fn, true);
q.setBoost(1000);
qtest(q, new int[] {2,3});
}
}
// TODO: test the payloadnear query too!
}