Skip to content

Commit dfdab9c

Browse files
committed
refactored basefilter and merging
1 parent 0456ca2 commit dfdab9c

27 files changed

+628
-312
lines changed

src/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@
107107
<Compile Include="Internals\Inferno\HostNameWithPathTests.cs" />
108108
<Compile Include="Internals\Inferno\MapTypeNamesTests.cs" />
109109
<Compile Include="Internals\Serialize\OptOutTests.cs" />
110-
<Compile Include="Search\Filter\BoolQueryMerges\BoolQueryMergesTests.cs" />
110+
<Compile Include="Search\Query\BoolQueryMerges\BoolQueryMergesTests.cs" />
111+
<Compile Include="Search\Filter\BoolFilterMerges\BoolFilterMergesTests.cs" />
111112
<Compile Include="Search\Filter\Singles\HasParentFilterJson.cs" />
112113
<Compile Include="Search\Query\Singles\HasParentQueryJson.cs" />
113114
<Compile Include="Search\Query\Singles\MultiMatch\MultiMatchJson.cs" />
@@ -360,31 +361,52 @@
360361
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
361362
</None>
362363
<None Include="packages.config" />
363-
<None Include="Search\Filter\BoolQueryMerges\ShouldNotJoinMustNotIntoMustStrictQueryInverse.json">
364+
<None Include="Search\Query\BoolQueryMerges\ShouldNotJoinMustNotIntoMustStrictQueryInverse.json">
364365
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
365366
</None>
366-
<None Include="Search\Filter\BoolQueryMerges\ShouldNotJoinMustNotIntoMustStrictQuery.json">
367+
<None Include="Search\Query\BoolQueryMerges\ShouldNotJoinMustNotIntoMustStrictQuery.json">
367368
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
368369
</None>
369-
<None Include="Search\Filter\BoolQueryMerges\ShouldJoinMustNotIntoMustQuery.json">
370+
<None Include="Search\Query\BoolQueryMerges\ShouldJoinMustNotIntoMustQuery.json">
370371
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
371372
</None>
372-
<None Include="Search\Filter\BoolQueryMerges\ShouldJoinIntoMustQuery.json">
373+
<None Include="Search\Query\BoolQueryMerges\ShouldJoinIntoMustQuery.json">
373374
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
374375
</None>
375-
<None Include="Search\Filter\BoolQueryMerges\ShouldNotJoinIntoStrictMustQuery.json">
376+
<None Include="Search\Query\BoolQueryMerges\ShouldNotJoinIntoStrictMustQuery.json">
376377
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
377378
</None>
378-
<None Include="Search\Filter\BoolQueryMerges\ShouldNotJoinIntoShouldQueryWithMinimumMatchPercentage.json">
379+
<None Include="Search\Query\BoolQueryMerges\ShouldNotJoinIntoShouldQueryWithMinimumMatchPercentage.json">
379380
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
380381
</None>
381-
<None Include="Search\Filter\BoolQueryMerges\ShouldNotJoinIntoShouldQueryWithMinimumMatch.json">
382+
<None Include="Search\Query\BoolQueryMerges\ShouldNotJoinIntoShouldQueryWithMinimumMatch.json">
382383
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
383384
</None>
384-
<None Include="Search\Filter\BoolQueryMerges\ShouldJoinIntoNonStrictShouldQuery.json">
385+
<None Include="Search\Query\BoolQueryMerges\ShouldJoinIntoNonStrictShouldQuery.json">
385386
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
386387
</None>
387-
<None Include="Search\Filter\BoolQueryMerges\ShouldNotJoinIntoStrictShouldQuery.json">
388+
<None Include="Search\Query\BoolQueryMerges\ShouldNotJoinIntoStrictShouldQuery.json">
389+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
390+
</None>
391+
<None Include="Search\Filter\BoolFilterMerges\ShouldJoinIntoMustFilter.json">
392+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
393+
</None>
394+
<None Include="Search\Filter\BoolFilterMerges\ShouldJoinIntoNonStrictShouldFilter.json">
395+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
396+
</None>
397+
<None Include="Search\Filter\BoolFilterMerges\ShouldJoinMustNotIntoMustFilter.json">
398+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
399+
</None>
400+
<None Include="Search\Filter\BoolFilterMerges\ShouldNotJoinIntoStrictMustFilter.json">
401+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
402+
</None>
403+
<None Include="Search\Filter\BoolFilterMerges\ShouldNotJoinIntoStrictShouldFilter.json">
404+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
405+
</None>
406+
<None Include="Search\Filter\BoolFilterMerges\ShouldNotJoinMustNotIntoMustStrictFilter.json">
407+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
408+
</None>
409+
<None Include="Search\Filter\BoolFilterMerges\ShouldNotJoinMustNotIntoMustStrictFilterInverse.json">
388410
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
389411
</None>
390412
<None Include="Search\Query\Singles\MultiMatch\TestMultiMatchJson.json" />
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System.Reflection;
2+
using NUnit.Framework;
3+
using Nest.Tests.MockData.Domain;
4+
5+
namespace Nest.Tests.Unit.Search.Filter.BoolFilterMerges
6+
{
7+
[TestFixture]
8+
public class BoolFilterMergesTests : BaseJsonTests
9+
{
10+
[Test]
11+
public void ShouldNotJoinIntoStrictShouldFilter()
12+
{
13+
var s = new SearchDescriptor<ElasticSearchProject>()
14+
.Filter(q =>
15+
q.Strict().Bool(
16+
bf=>bf.Should(
17+
qq=>qq.Term(f => f.Name, "foo2"),
18+
qq => qq.Term(f => f.Name, "bar2")
19+
)
20+
)
21+
|| q.Term(f => f.Name, "blah2")
22+
);
23+
this.JsonEquals(s, MethodBase.GetCurrentMethod());
24+
}
25+
26+
27+
[Test]
28+
public void ShouldJoinIntoNonStrictShouldFilter()
29+
{
30+
var s = new SearchDescriptor<ElasticSearchProject>()
31+
.Filter(q =>
32+
q.Bool(
33+
bf => bf.Should(
34+
qq => qq.Term(f => f.Name, "foo2"),
35+
qq => qq.Term(f => f.Name, "bar2")
36+
)
37+
)
38+
|| q.Term(f => f.Name, "blah2")
39+
);
40+
this.JsonEquals(s, MethodBase.GetCurrentMethod());
41+
}
42+
43+
44+
[Test]
45+
public void ShouldJoinIntoMustFilter()
46+
{
47+
var s = new SearchDescriptor<ElasticSearchProject>()
48+
.Filter(q =>
49+
q.Bool(
50+
bf => bf.Must(
51+
qq => qq.Term(f => f.Name, "foo2"),
52+
qq => qq.Term(f => f.Name, "bar2")
53+
)
54+
)
55+
&& q.Term(f => f.Name, "blah2")
56+
);
57+
this.JsonEquals(s, MethodBase.GetCurrentMethod());
58+
}
59+
[Test]
60+
public void ShouldJoinMustNotIntoMustFilter()
61+
{
62+
var s = new SearchDescriptor<ElasticSearchProject>()
63+
.Filter(q =>
64+
q.Bool(
65+
bf => bf.Must(
66+
qq => qq.Term(f => f.Name, "foo2"),
67+
qq => qq.Term(f => f.Name, "bar2")
68+
)
69+
)
70+
&& !q.Term(f => f.Name, "blah2")
71+
);
72+
this.JsonEquals(s, MethodBase.GetCurrentMethod());
73+
}
74+
75+
[Test]
76+
public void ShouldNotJoinMustNotIntoMustStrictFilter()
77+
{
78+
var s = new SearchDescriptor<ElasticSearchProject>()
79+
.Filter(q =>
80+
q.Strict().Bool(
81+
bf => bf.Must(
82+
qq => qq.Term(f => f.Name, "foo2"),
83+
qq => qq.Term(f => f.Name, "bar2")
84+
)
85+
)
86+
&& !q.Term(f => f.Name, "blah2")
87+
);
88+
this.JsonEquals(s, MethodBase.GetCurrentMethod());
89+
}
90+
91+
[Test]
92+
public void ShouldNotJoinMustNotIntoMustStrictFilterInverse()
93+
{
94+
var s = new SearchDescriptor<ElasticSearchProject>()
95+
.Filter(q =>
96+
!q.Term(f => f.Name, "blah2")
97+
&& q.Strict().Bool(
98+
bf => bf.Must(
99+
qq => qq.Term(f => f.Name, "foo2"),
100+
qq => qq.Term(f => f.Name, "bar2")
101+
)
102+
)
103+
);
104+
this.JsonEquals(s, MethodBase.GetCurrentMethod());
105+
}
106+
107+
[Test]
108+
public void ShouldNotJoinIntoStrictMustFilter()
109+
{
110+
var s = new SearchDescriptor<ElasticSearchProject>()
111+
.Filter(q =>
112+
q.Strict().Bool(
113+
bf => bf.Must(
114+
qq => qq.Term(f => f.Name, "foo2"),
115+
qq => qq.Term(f => f.Name, "bar2")
116+
)
117+
)
118+
&& q.Term(f => f.Name, "blah2")
119+
);
120+
this.JsonEquals(s, MethodBase.GetCurrentMethod());
121+
}
122+
123+
}
124+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"filter": {
3+
"bool": {
4+
"must": [
5+
{
6+
"term": {
7+
"name": "foo2"
8+
}
9+
},
10+
{
11+
"term": {
12+
"name": "bar2"
13+
}
14+
},
15+
{
16+
"term": {
17+
"name": "blah2"
18+
}
19+
}
20+
]
21+
}
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"filter": {
3+
"bool": {
4+
"should": [
5+
{
6+
"term": {
7+
"name": "foo2"
8+
}
9+
},
10+
{
11+
"term": {
12+
"name": "bar2"
13+
}
14+
},
15+
{
16+
"term": {
17+
"name": "blah2"
18+
}
19+
}
20+
]
21+
}
22+
}
23+
}

src/Nest.Tests.Unit/Search/Filter/BoolQueryMerges/ShouldNotJoinMustNotIntoMustStrictQuery.json renamed to src/Nest.Tests.Unit/Search/Filter/BoolFilterMerges/ShouldJoinMustNotIntoMustFilter.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
{
2-
"query": {
2+
"filter": {
33
"bool": {
44
"must": [
55
{
66
"term": {
7-
"name": {
8-
"value": "foo2"
9-
}
7+
"name": "foo2"
108
}
119
},
1210
{
1311
"term": {
14-
"name": {
15-
"value": "bar2"
16-
}
12+
"name": "bar2"
1713
}
1814
}
1915
],
2016
"must_not": [
2117
{
2218
"term": {
23-
"name": {
24-
"value": "blah2"
25-
}
19+
"name": "blah2"
2620
}
2721
}
2822
]
29-
}
23+
}
3024
}
3125
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"filter": {
3+
"bool": {
4+
"must": [
5+
{
6+
"bool": {
7+
"must": [
8+
{
9+
"term": {
10+
"name": "foo2"
11+
}
12+
},
13+
{
14+
"term": {
15+
"name": "bar2"
16+
}
17+
}
18+
]
19+
}
20+
},
21+
{
22+
"term": {
23+
"name": "blah2"
24+
}
25+
}
26+
]
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"filter": {
3+
"bool": {
4+
"should": [
5+
{
6+
"bool": {
7+
"should": [
8+
{
9+
"term": {
10+
"name": "foo2"
11+
}
12+
},
13+
{
14+
"term": {
15+
"name": "bar2"
16+
}
17+
}
18+
]
19+
}
20+
},
21+
{
22+
"term": {
23+
"name": "blah2"
24+
}
25+
}
26+
]
27+
}
28+
}
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"filter": {
3+
"bool": {
4+
"must": [
5+
{
6+
"bool": {
7+
"must": [
8+
{
9+
"term": {
10+
"name": "foo2"
11+
}
12+
},
13+
{
14+
"term": {
15+
"name": "bar2"
16+
}
17+
}
18+
]
19+
}
20+
}
21+
],
22+
"must_not": [
23+
{
24+
"term": {
25+
"name": "blah2"
26+
}
27+
}
28+
]
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)