@@ -16,14 +16,15 @@ public interface IBoolQuery : IQuery
16
16
IEnumerable < QueryContainer > Must { get ; set ; }
17
17
18
18
/// <summary>
19
- /// The clause (query) must not appear in the matching documents. Note that it is not possible to search on documents that only consists of a must_not clauses.
19
+ /// The clause (query) must not appear in the matching documents.
20
+ /// Note that it is not possible to search on documents that only consists of a must_not clauses.
20
21
/// </summary>
21
22
[ JsonProperty ( "must_not" , DefaultValueHandling = DefaultValueHandling . Ignore ) ]
22
23
IEnumerable < QueryContainer > MustNot { get ; set ; }
23
24
24
25
/// <summary>
25
26
/// The clause (query) should appear in the matching document. A boolean query with no must clauses, one or more should clauses must match a document.
26
- /// The minimum number of should clauses to match can be set using minimum_should_match parameter .
27
+ /// The minimum number of should clauses to match can be set using <see cref="MinimumShouldMatch"/> .
27
28
/// </summary>
28
29
[ JsonProperty ( "should" , DefaultValueHandling = DefaultValueHandling . Ignore ) ]
29
30
IEnumerable < QueryContainer > Should { get ; set ; }
@@ -69,7 +70,7 @@ public class BoolQuery : QueryBase, IBoolQuery
69
70
70
71
/// <summary>
71
72
/// The clause (query) should appear in the matching document. A boolean query with no must clauses, one or more should clauses must match a document.
72
- /// The minimum number of should clauses to match can be set using minimum_should_match parameter .
73
+ /// The minimum number of should clauses to match can be set using <see cref="MinimumShouldMatch"/> .
73
74
/// </summary>
74
75
public IEnumerable < QueryContainer > Should { get ; set ; }
75
76
@@ -96,15 +97,18 @@ public class BoolQuery : QueryBase, IBoolQuery
96
97
protected override bool Conditionless => IsConditionless ( this ) ;
97
98
internal static bool IsConditionless ( IBoolQuery q )
98
99
{
99
- if ( ! q . Must . HasAny ( ) && ! q . Should . HasAny ( ) && ! q . MustNot . HasAny ( ) && ! q . Filter . HasAny ( ) )
100
- return true ;
100
+ var musts = q . Must == null || q . Must . All ( qq => qq . IsConditionless ( ) ) ;
101
+ if ( ! musts ) return false ;
102
+
103
+ var shoulds = q . Should == null || q . Should . All ( qq => qq . IsConditionless ( ) ) ;
104
+ if ( ! shoulds ) return false ;
105
+
106
+ var filters = q . Filter == null || q . Filter . All ( qq => qq . IsConditionless ( ) ) ;
107
+ if ( ! filters ) return false ;
101
108
102
- var mustNots = q . MustNot == null || q . MustNot . HasAny ( ) && q . MustNot . All ( qq => qq . IsConditionless ( ) ) ;
103
- var shoulds = q . Should == null || q . Should . HasAny ( ) && q . Should . All ( qq => qq . IsConditionless ( ) ) ;
104
- var musts = q . Must == null || q . Must . HasAny ( ) && q . Must . All ( qq => qq . IsConditionless ( ) ) ;
105
- var filters = q . Filter == null || ( q . Filter . HasAny ( ) && q . Filter . All ( qq => qq . IsConditionless ( ) ) ) ;
109
+ var mustNots = q . MustNot == null || q . MustNot . All ( qq => qq . IsConditionless ( ) ) ;
106
110
107
- return mustNots && shoulds && musts && filters ;
111
+ return mustNots ;
108
112
}
109
113
}
110
114
@@ -182,7 +186,7 @@ public BoolQueryDescriptor<T> MustNot(params QueryContainer[] queries) =>
182
186
183
187
/// <summary>
184
188
/// The clause (query) should appear in the matching document. A boolean query with no must clauses, one or more should clauses must match a document.
185
- /// The minimum number of should clauses to match can be set using minimum_should_match parameter .
189
+ /// The minimum number of should clauses to match can be set using <see cref="MinimumShouldMatch"/> .
186
190
/// </summary>
187
191
/// <param name="queries"></param>
188
192
/// <returns></returns>
@@ -191,7 +195,7 @@ public BoolQueryDescriptor<T> Should(params Func<QueryContainerDescriptor<T>, Qu
191
195
192
196
/// <summary>
193
197
/// The clause (query) should appear in the matching document. A boolean query with no must clauses, one or more should clauses must match a document.
194
- /// The minimum number of should clauses to match can be set using minimum_should_match parameter .
198
+ /// The minimum number of should clauses to match can be set using <see cref="MinimumShouldMatch"/> .
195
199
/// </summary>
196
200
/// <param name="queries"></param>
197
201
/// <returns></returns>
@@ -200,7 +204,7 @@ public BoolQueryDescriptor<T> Should(IEnumerable<Func<QueryContainerDescriptor<T
200
204
201
205
/// <summary>
202
206
/// The clause (query) should appear in the matching document. A boolean query with no must clauses, one or more should clauses must match a document.
203
- /// The minimum number of should clauses to match can be set using minimum_should_match parameter .
207
+ /// The minimum number of should clauses to match can be set using <see cref="MinimumShouldMatch"/> .
204
208
/// </summary>
205
209
/// <param name="queries"></param>
206
210
/// <returns></returns>
0 commit comments