mirror of https://github.com/apache/lucene.git
LUCENE-6590: Fix BooleanQuery to not propagate query boosts twice.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1701742 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
962313b83b
commit
e21c1994b7
|
@ -43,7 +43,6 @@ final class BooleanWeight extends Weight {
|
|||
final boolean disableCoord;
|
||||
final boolean needsScores;
|
||||
final float coords[];
|
||||
float boost = 1f;
|
||||
|
||||
BooleanWeight(BooleanQuery query, IndexSearcher searcher, boolean needsScores, boolean disableCoord) throws IOException {
|
||||
super(query);
|
||||
|
@ -106,8 +105,6 @@ final class BooleanWeight extends Weight {
|
|||
i += 1;
|
||||
}
|
||||
|
||||
sum *= boost * boost; // boost each sub-weight
|
||||
|
||||
return sum ;
|
||||
}
|
||||
|
||||
|
@ -129,7 +126,6 @@ final class BooleanWeight extends Weight {
|
|||
|
||||
@Override
|
||||
public void normalize(float norm, float boost) {
|
||||
this.boost = boost;
|
||||
for (Weight w : weights) {
|
||||
// normalize all clauses, (even if non-scoring in case of side affects)
|
||||
w.normalize(norm, boost);
|
||||
|
|
|
@ -118,7 +118,6 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
|
|||
/** The Weights for our subqueries, in 1-1 correspondence with disjuncts */
|
||||
protected final ArrayList<Weight> weights = new ArrayList<>(); // The Weight's for our subqueries, in 1-1 correspondence with disjuncts
|
||||
private final boolean needsScores;
|
||||
private float boost;
|
||||
|
||||
/** Construct the Weight for this Query searched by searcher. Recursively construct subquery weights. */
|
||||
public DisjunctionMaxWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
|
||||
|
@ -127,7 +126,6 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
|
|||
weights.add(searcher.createWeight(disjunctQuery, needsScores));
|
||||
}
|
||||
this.needsScores = needsScores;
|
||||
this.boost = 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,13 +145,12 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
|
|||
max = Math.max(max, sub);
|
||||
|
||||
}
|
||||
return (((sum - max) * tieBreakerMultiplier * tieBreakerMultiplier) + max) * boost * boost;
|
||||
return (((sum - max) * tieBreakerMultiplier * tieBreakerMultiplier) + max);
|
||||
}
|
||||
|
||||
/** Apply the computed normalization factor to our subqueries */
|
||||
@Override
|
||||
public void normalize(float norm, float boost) {
|
||||
this.boost = boost;
|
||||
for (Weight wt : weights) {
|
||||
wt.normalize(norm, boost);
|
||||
}
|
||||
|
|
|
@ -214,4 +214,20 @@ public class TestSimpleSearchEquivalence extends SearchEquivalenceTestBase {
|
|||
|
||||
assertSameScores(q1, q2);
|
||||
}
|
||||
|
||||
public void testBooleanBoostPropagation() throws Exception {
|
||||
float boost1 = random().nextFloat();
|
||||
Query tq = new BoostQuery(new TermQuery(randomTerm()), boost1);
|
||||
|
||||
float boost2 = random().nextFloat();
|
||||
// Applying boost2 over the term or boolean query should have the same effect
|
||||
Query q1 = new BoostQuery(tq, boost2);
|
||||
Query q2 = new BooleanQuery.Builder()
|
||||
.add(tq, Occur.MUST)
|
||||
.add(tq, Occur.FILTER)
|
||||
.build();
|
||||
q2 = new BoostQuery(q2, boost2);
|
||||
|
||||
assertSameScores(q1, q2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue