diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java index ae4fe864c0f..7ec0185dc6f 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java @@ -744,6 +744,72 @@ public class TestBooleanCoord extends LuceneTestCase { assertScore(3, bq.build()); } + // nested cases, make sure conjunctions propagate scoring + + public void testConjunctionNested() throws Exception { + BooleanQuery.Builder inner = new BooleanQuery.Builder(); + inner.add(term("A"), BooleanClause.Occur.MUST); + inner.add(term("B"), BooleanClause.Occur.MUST); + BooleanQuery.Builder outer = new BooleanQuery.Builder(); + outer.add(inner.build(), BooleanClause.Occur.MUST); + outer.add(term("C"), BooleanClause.Occur.MUST); + float innerScore = (1 + 1) * 2/(2f+1); + float outerScore = (innerScore + 1) * 2/(2f+1); + assertScore(outerScore, outer.build()); + } + + public void testConjunctionNestedOuterCoordDisabled() throws Exception { + BooleanQuery.Builder inner = new BooleanQuery.Builder(); + inner.add(term("A"), BooleanClause.Occur.MUST); + inner.add(term("B"), BooleanClause.Occur.MUST); + BooleanQuery.Builder outer = new BooleanQuery.Builder(); + outer.setDisableCoord(true); + outer.add(inner.build(), BooleanClause.Occur.MUST); + outer.add(term("C"), BooleanClause.Occur.MUST); + float innerScore = (1 + 1) * 2/(2f+1); + float outerScore = (innerScore + 1); + assertScore(outerScore, outer.build()); + } + + public void testConjunctionNestedInnerCoordDisabled() throws Exception { + BooleanQuery.Builder inner = new BooleanQuery.Builder(); + inner.setDisableCoord(true); + inner.add(term("A"), BooleanClause.Occur.MUST); + inner.add(term("B"), BooleanClause.Occur.MUST); + BooleanQuery.Builder outer = new BooleanQuery.Builder(); + outer.add(inner.build(), BooleanClause.Occur.MUST); + outer.add(term("C"), BooleanClause.Occur.MUST); + float innerScore = (1 + 1); + float outerScore = (innerScore + 1) * 2/(2f+1); + assertScore(outerScore, outer.build()); + } + + public void testConjunctionNestedCoordDisabledEverywhere() throws Exception { + BooleanQuery.Builder inner = new BooleanQuery.Builder(); + inner.setDisableCoord(true); + inner.add(term("A"), BooleanClause.Occur.MUST); + inner.add(term("B"), BooleanClause.Occur.MUST); + BooleanQuery.Builder outer = new BooleanQuery.Builder(); + outer.setDisableCoord(true); + outer.add(inner.build(), BooleanClause.Occur.MUST); + outer.add(term("C"), BooleanClause.Occur.MUST); + float innerScore = (1 + 1); + float outerScore = (innerScore + 1); + assertScore(outerScore, outer.build()); + } + + public void testConjunctionNestedSingle() throws Exception { + BooleanQuery.Builder inner = new BooleanQuery.Builder(); + inner.add(term("A"), BooleanClause.Occur.MUST); + inner.add(term("B"), BooleanClause.Occur.MUST); + BooleanQuery.Builder outer = new BooleanQuery.Builder(); + outer.add(inner.build(), BooleanClause.Occur.MUST); + float innerScore = (1 + 1) * 2/(2f+1); + // LUCENE-4300: coord(1,1) is always treated as 1 + float outerScore = innerScore * 1; + assertScore(outerScore, outer.build()); + } + /** asserts score for our single matching good doc */ private void assertScore(final float expected, Query query) throws Exception { // test in-order