mirror of https://github.com/apache/lucene.git
LUCENE-6042: fix CustomScoreQuery explain to properly factor boost
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1636552 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2e0eea7346
commit
35375d57b9
|
@ -204,6 +204,9 @@ Bug Fixes
|
|||
* LUCENE-6041: Remove sugar methods FieldInfo.isIndexed and
|
||||
FieldInfo.hasDocValues. (Robert Muir, Mike McCandless)
|
||||
|
||||
* LUCENE-6042: CustomScoreQuery explain was incorrect in some cases,
|
||||
such as when nested inside a boolean query. (Denis Lantsman via Robert Muir)
|
||||
|
||||
Documentation
|
||||
|
||||
* LUCENE-5392: Add/improve analysis package documentation to reflect
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.lucene.search.spans.*;
|
|||
* on the assumption that if the explanations work out right for them,
|
||||
* they should work for anything.
|
||||
*/
|
||||
public class TestComplexExplanations extends TestExplanations {
|
||||
public class TestComplexExplanations extends BaseExplanationTestCase {
|
||||
|
||||
/**
|
||||
* Override the Similarity used in our searcher with one that plays
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.apache.lucene.index.Term;
|
|||
/**
|
||||
* TestExplanations subclass focusing on basic query types
|
||||
*/
|
||||
public class TestSimpleExplanations extends TestExplanations {
|
||||
public class TestSimpleExplanations extends BaseExplanationTestCase {
|
||||
|
||||
// we focus on queries that don't rewrite to other queries.
|
||||
// if we get those covered well, then the ones that rewrite should
|
||||
|
|
|
@ -20,14 +20,14 @@ package org.apache.lucene.search.payloads;
|
|||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.similarities.DefaultSimilarity;
|
||||
import org.apache.lucene.search.similarities.Similarity;
|
||||
import org.apache.lucene.search.TestExplanations;
|
||||
import org.apache.lucene.search.BaseExplanationTestCase;
|
||||
import org.apache.lucene.search.spans.SpanQuery;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
||||
/**
|
||||
* TestExplanations subclass focusing on payload queries
|
||||
*/
|
||||
public class TestPayloadExplanations extends TestExplanations {
|
||||
public class TestPayloadExplanations extends BaseExplanationTestCase {
|
||||
private PayloadFunction functions[] = new PayloadFunction[] {
|
||||
new AveragePayloadFunction(),
|
||||
new MinPayloadFunction(),
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.apache.lucene.search.*;
|
|||
/**
|
||||
* TestExplanations subclass focusing on span queries
|
||||
*/
|
||||
public class TestSpanExplanations extends TestExplanations {
|
||||
public class TestSpanExplanations extends BaseExplanationTestCase {
|
||||
|
||||
/* simple SpanTermQueries */
|
||||
|
||||
|
|
|
@ -263,11 +263,11 @@ public class CustomScoreQuery extends Query {
|
|||
valSrcExpls[i] = valSrcWeights[i].explain(info, doc);
|
||||
}
|
||||
Explanation customExp = CustomScoreQuery.this.getCustomScoreProvider(info).customExplain(doc,subQueryExpl,valSrcExpls);
|
||||
float sc = getBoost() * customExp.getValue();
|
||||
float sc = queryWeight * customExp.getValue();
|
||||
Explanation res = new ComplexExplanation(
|
||||
true, sc, CustomScoreQuery.this.toString() + ", product of:");
|
||||
res.addDetail(customExp);
|
||||
res.addDetail(new Explanation(getBoost(), "queryBoost")); // actually using the q boost as q weight (== weight value)
|
||||
res.addDetail(new Explanation(queryWeight, "queryWeight"));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.apache.lucene.queries;
|
||||
|
||||
/*
|
||||
* 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.queries.function.FunctionQuery;
|
||||
import org.apache.lucene.queries.function.valuesource.ConstValueSource;
|
||||
import org.apache.lucene.search.BaseExplanationTestCase;
|
||||
import org.apache.lucene.search.BooleanClause;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
|
||||
public class TestCustomScoreExplanations extends BaseExplanationTestCase {
|
||||
public void testOneTerm() throws Exception {
|
||||
Query q = new TermQuery(new Term(FIELD, "w1"));
|
||||
CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
|
||||
qtest(csq, new int[] { 0,1,2,3 });
|
||||
}
|
||||
|
||||
public void testBoost() throws Exception {
|
||||
Query q = new TermQuery(new Term(FIELD, "w1"));
|
||||
CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
|
||||
csq.setBoost(4);
|
||||
qtest(csq, new int[] { 0,1,2,3 });
|
||||
}
|
||||
|
||||
public void testTopLevelBoost() throws Exception {
|
||||
Query q = new TermQuery(new Term(FIELD, "w1"));
|
||||
CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
|
||||
BooleanQuery bq = new BooleanQuery();
|
||||
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
|
||||
bq.add(csq, BooleanClause.Occur.MUST);
|
||||
bq.setBoost(6);
|
||||
qtest(bq, new int[] { 0,1,2,3 });
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ import org.junit.BeforeClass;
|
|||
*
|
||||
* @see "Subclasses for actual tests"
|
||||
*/
|
||||
public class TestExplanations extends LuceneTestCase {
|
||||
public abstract class BaseExplanationTestCase extends LuceneTestCase {
|
||||
protected static IndexSearcher searcher;
|
||||
protected static IndexReader reader;
|
||||
protected static Directory directory;
|
||||
|
@ -211,12 +211,4 @@ public class TestExplanations extends LuceneTestCase {
|
|||
bq.add(new TermQuery(new Term(FIELD,"w1")), BooleanClause.Occur.SHOULD);
|
||||
return bq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholder: JUnit freaks if you don't have one test ... making
|
||||
* class abstract doesn't help
|
||||
*/
|
||||
public void testNoop() {
|
||||
/* NOOP */
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue