@@ -19,6 +19,10 @@ public interface IFunctionScoreQuery : IQuery
1919 [ JsonConverter ( typeof ( CompositeJsonConverter < ReadAsTypeConverter < QueryDescriptor < object > > , CustomJsonConverter > ) ) ]
2020 IQueryContainer Query { get ; set ; }
2121
22+ [ JsonProperty ( PropertyName = "filter" ) ]
23+ [ JsonConverter ( typeof ( CompositeJsonConverter < ReadAsTypeConverter < FilterContainer > , CustomJsonConverter > ) ) ]
24+ IFilterContainer Filter { get ; set ; }
25+
2226 [ JsonProperty ( PropertyName = "score_mode" ) ]
2327 [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
2428 FunctionScoreMode ? ScoreMode { get ; set ; }
@@ -57,6 +61,7 @@ protected override void WrapInContainer(IQueryContainer container)
5761 public string Name { get ; set ; }
5862 public IEnumerable < IFunctionScoreFunction > Functions { get ; set ; }
5963 public IQueryContainer Query { get ; set ; }
64+ public IFilterContainer Filter { get ; set ; }
6065 public FunctionScoreMode ? ScoreMode { get ; set ; }
6166 public FunctionBoostMode ? BoostMode { get ; set ; }
6267 public float ? MaxBoost { get ; set ; }
@@ -81,6 +86,8 @@ public class FunctionScoreQueryDescriptor<T> : IFunctionScoreQuery where T : cla
8186
8287 IQueryContainer IFunctionScoreQuery . Query { get ; set ; }
8388
89+ IFilterContainer IFunctionScoreQuery . Filter { get ; set ; }
90+
8491 FunctionScoreMode ? IFunctionScoreQuery . ScoreMode { get ; set ; }
8592
8693 FunctionBoostMode ? IFunctionScoreQuery . BoostMode { get ; set ; }
@@ -109,10 +116,9 @@ bool IQuery.IsConditionless
109116 {
110117 get
111118 {
112- return _forcedConditionless || ( ( Self . Query == null || Self . Query . IsConditionless )
113- && Self . RandomScore == null
114- && Self . ScriptScore == null
115- && ! Self . Functions . HasAny ( ) ) ;
119+ return _forcedConditionless
120+ || ( ( Self . Query == null || Self . Query . IsConditionless || Self . Filter == null || Self . Filter . IsConditionless )
121+ && Self . RandomScore == null && Self . ScriptScore == null && ! Self . Functions . HasAny ( ) ) ;
116122 }
117123 }
118124
@@ -134,10 +140,19 @@ public FunctionScoreQueryDescriptor<T> Query(Func<QueryDescriptor<T>, QueryConta
134140 querySelector . ThrowIfNull ( "querySelector" ) ;
135141 var query = new QueryDescriptor < T > ( ) ;
136142 var q = querySelector ( query ) ;
137- Self . Query = q . IsConditionless ? null : q ;
143+ Self . Query = q . IsConditionless ? null : q ;
138144 return this ;
139145 }
140146
147+ public FunctionScoreQueryDescriptor < T > Filter ( Func < FilterDescriptor < T > , FilterContainer > filterSelector )
148+ {
149+ filterSelector . ThrowIfNull ( "filterSelector" ) ;
150+ var filter = new FilterDescriptor < T > ( ) ;
151+ var f = filterSelector ( filter ) ;
152+ Self . Filter = f . IsConditionless ? null : f ;
153+ return this ;
154+ }
155+
141156 public FunctionScoreQueryDescriptor < T > Functions ( params Func < FunctionScoreFunctionsDescriptor < T > , FunctionScoreFunction < T > > [ ] functions )
142157 {
143158 var descriptor = new FunctionScoreFunctionsDescriptor < T > ( ) ;
0 commit comments