Skip to content

Commit 9b927a0

Browse files
committed
add failing test for #1695, if only the rightContainer is locked we can not join onto it either
1 parent ac18aad commit 9b927a0

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

src/Nest/QueryDsl/Abstractions/Query/BoolQueryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal static QueryContainer CombineAsMust(this QueryContainer leftContainer,
3131

3232
internal static QueryContainer CombineAsShould(this QueryContainer leftContainer, QueryContainer rightContainer)
3333
{
34-
if (!leftContainer.CanMergeShould() || !leftContainer.CanMergeShould())
34+
if (!leftContainer.CanMergeShould() || !rightContainer.CanMergeShould())
3535
return CreateShouldContainer(new List<QueryContainer> { leftContainer, rightContainer });
3636

3737
var lBoolQuery = leftContainer.Self().Bool;

src/Tests/QueryDsl/BoolDsl/BoolDsl.doc.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,35 @@ [U] public void MixAndMatchMinimumShouldMatch() =>
252252

253253
[U] public void DoNotCombineLockedBools() =>
254254
Assert(
255-
q => q.Bool(b=>b.Name("firstBool").Should(mq=>mq.Query()))
256-
|| q.Bool(b=>b.Name("secondBool").Should(mq=>mq.Query())),
257-
new BoolQuery { Name = "firstBool", Should = new QueryContainer[] { Query } }
258-
|| new BoolQuery { Name = "secondBool", Should = new QueryContainer[] { Query } },
259-
c=>
260-
{
261-
c.Bool.Should.Should().HaveCount(2);
262-
var nestedBool = c.Bool.Should.First() as IQueryContainer;
263-
nestedBool.Bool.Should.Should().HaveCount(1);
264-
nestedBool.Bool.Name.Should().Be("firstBool");
265-
});
255+
q => q.Bool(b=>b.Name("leftBool").Should(mq=>mq.Query()))
256+
|| q.Bool(b=>b.Name("rightBool").Should(mq=>mq.Query())),
257+
new BoolQuery { Name = "leftBool", Should = new QueryContainer[] { Query } }
258+
|| new BoolQuery { Name = "rightBool", Should = new QueryContainer[] { Query } },
259+
c=>AssertDoesNotJoinOntoLockedBool(c, "leftBool"));
260+
261+
[U] public void DoNotCombineRightLockedBool() =>
262+
Assert(
263+
q => q.Bool(b=>b.Should(mq=>mq.Query()))
264+
|| q.Bool(b=>b.Name("rightBool").Should(mq=>mq.Query())),
265+
new BoolQuery { Should = new QueryContainer[] { Query } }
266+
|| new BoolQuery { Name = "rightBool", Should = new QueryContainer[] { Query } },
267+
c=>AssertDoesNotJoinOntoLockedBool(c, "rightBool"));
268+
269+
[U] public void DoNotCombineLeftLockedBool() =>
270+
Assert(
271+
q => q.Bool(b=>b.Name("leftBool").Should(mq=>mq.Query()))
272+
|| q.Bool(b=>b.Should(mq=>mq.Query())),
273+
new BoolQuery { Name = "leftBool", Should = new QueryContainer[] { Query } }
274+
|| new BoolQuery { Should = new QueryContainer[] { Query } },
275+
c=>AssertDoesNotJoinOntoLockedBool(c, "leftBool"));
276+
277+
private static void AssertDoesNotJoinOntoLockedBool(IQueryContainer c, string firstName)
278+
{
279+
c.Bool.Should.Should().HaveCount(2);
280+
var nestedBool = c.Bool.Should.Cast<IQueryContainer>().First(b=>!string.IsNullOrEmpty(b.Bool?.Name));
281+
nestedBool.Bool.Should.Should().HaveCount(1);
282+
nestedBool.Bool.Name.Should().Be(firstName);
283+
}
266284

267285

268286
private void Assert(

src/Tests/QueryDsl/BoolDsl/Operators/OrOperatorUsageTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ [U] public void Or()
1717
b.Filter.Should().BeNull();
1818
});
1919

20+
ReturnsBool(Query || Query || ConditionlessQuery, q => q.Query() || q.Query() || q.ConditionlessQuery(), b =>
21+
{
22+
b.Should.Should().NotBeEmpty().And.HaveCount(2);
23+
b.Must.Should().BeNull();
24+
b.MustNot.Should().BeNull();
25+
b.Filter.Should().BeNull();
26+
});
27+
2028
ReturnsBool(Query || Query || ConditionlessQuery, q => q.Query() || q.Query() || q.ConditionlessQuery(), b =>
2129
{
2230
b.Should.Should().NotBeEmpty().And.HaveCount(2);
@@ -58,8 +66,8 @@ [U] public void Or()
5866
NullQuery || ConditionlessQuery || ConditionlessQuery || ConditionlessQuery,
5967
q=>q.NullQuery() || q.ConditionlessQuery() || q.ConditionlessQuery() || q.ConditionlessQuery()
6068
);
61-
6269
}
70+
6371
[U] public void CombiningManyUsingAggregate()
6472
{
6573
var lotsOfOrs = Enumerable.Range(0, 100).Aggregate(new QueryContainer(), (q, c) => q || Query, q => q);

0 commit comments

Comments
 (0)