mirror of https://github.com/apache/lucene.git
LUCENE-6585: add some tests that coord is applied properly for nested conjunctions
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1687404 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9dd97ffc42
commit
5a0a7728dc
|
@ -744,6 +744,72 @@ public class TestBooleanCoord extends LuceneTestCase {
|
||||||
assertScore(3, bq.build());
|
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 */
|
/** asserts score for our single matching good doc */
|
||||||
private void assertScore(final float expected, Query query) throws Exception {
|
private void assertScore(final float expected, Query query) throws Exception {
|
||||||
// test in-order
|
// test in-order
|
||||||
|
|
Loading…
Reference in New Issue