1- using System ;
2- using System . Collections ;
3- using System . Collections . Generic ;
4- using System . Linq ;
1+ using Nest . Resolvers ;
2+ using Newtonsoft . Json ;
3+ using Newtonsoft . Json . Converters ;
4+ using System ;
5+ using System . Collections ;
6+ using System . Collections . Generic ;
7+ using System . Linq ;
58using System . Linq . Expressions ;
6- using System . Text ;
7- using Elasticsearch . Net ;
8- using Nest . Resolvers ;
9- using Newtonsoft . Json ;
10- using Newtonsoft . Json . Converters ;
119
1210namespace Nest
1311{
@@ -33,7 +31,7 @@ public class FunctionScoreQueryDescriptor<T> : IQuery where T : class
3331 RandomScoreFunction _RandomScore { get ; set ; }
3432
3533 [ JsonProperty ( PropertyName = "script_score" ) ]
36- ScriptFilterDescriptor _ScriptScore { get ; set ; }
34+ ScriptFilterDescriptor _ScriptScore { get ; set ; }
3735
3836 bool IQuery . IsConditionless
3937 {
@@ -98,7 +96,7 @@ public FunctionScoreQueryDescriptor<T> ScriptScore(Action<ScriptFilterDescriptor
9896 this . _ScriptScore = descriptor ;
9997
10098 return this ;
101- }
99+ }
102100 }
103101
104102 public enum FunctionScoreMode
@@ -156,9 +154,16 @@ public BoostFactorFunction<T> BoostFactor(double value)
156154 var fn = new BoostFactorFunction < T > ( value ) ;
157155 this . _Functions . Add ( fn ) ;
158156 return fn ;
159- }
160-
161- public ScriptScoreFunction < T > ScriptScore ( Action < ScriptFilterDescriptor > scriptSelector )
157+ }
158+
159+ public FieldValueFactor < T > FieldValueFactor ( Action < FieldValueFactorDescriptor < T > > db )
160+ {
161+ var fn = new FieldValueFactor < T > ( db ) ;
162+ this . _Functions . Add ( fn ) ;
163+ return fn ;
164+ }
165+
166+ public ScriptScoreFunction < T > ScriptScore ( Action < ScriptFilterDescriptor > scriptSelector )
162167 {
163168 var fn = new ScriptScoreFunction < T > ( scriptSelector ) ;
164169 this . _Functions . Add ( fn ) ;
@@ -174,12 +179,45 @@ IEnumerator IEnumerable.GetEnumerator()
174179 {
175180 return _Functions . GetEnumerator ( ) ;
176181 }
177- }
178-
179- [ JsonObject ( MemberSerialization = MemberSerialization . OptIn ) ]
182+ }
183+
184+ [ JsonObject ( MemberSerialization = MemberSerialization . OptIn ) ]
180185 public class FunctionScoreFunction < T >
181186 {
182- }
187+ }
188+
189+
190+ public class FieldValueFactorDescriptor < T >
191+ {
192+ [ JsonProperty ( "field" ) ]
193+ internal PropertyPathMarker _Field { get ; set ; }
194+
195+ [ JsonProperty ( "factor" ) ]
196+ internal double _Factor { get ; set ; }
197+
198+ [ JsonProperty ( "modifier" ) ]
199+ [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
200+
201+ internal FieldValueFactorModifier _Modifier { get ; set ; }
202+
203+ public FieldValueFactorDescriptor < T > Field ( Expression < Func < T , object > > field )
204+ {
205+ this . _Field = field ;
206+ return this ;
207+ }
208+
209+ public FieldValueFactorDescriptor < T > Factor ( double factor )
210+ {
211+ this . _Factor = factor ;
212+ return this ;
213+ }
214+
215+ public FieldValueFactorDescriptor < T > Modifier ( FieldValueFactorModifier modifier )
216+ {
217+ this . _Modifier = modifier ;
218+ return this ;
219+ }
220+ }
183221
184222 public class FunctionScoreDecayFieldDescriptor
185223 {
@@ -303,9 +341,38 @@ public BoostFactorFunction(double boostFactor)
303341 {
304342 _BoostFactor = boostFactor ;
305343 }
306- }
307-
308- [ JsonObject ( MemberSerialization = MemberSerialization . OptIn ) ]
344+ }
345+
346+ [ JsonObject ( MemberSerialization = MemberSerialization . OptIn ) ]
347+ public class FieldValueFactor < T > : FunctionScoreFilteredFunction < T > where T : class
348+ {
349+ [ JsonProperty ( PropertyName = "field_value_factor" ) ]
350+ internal FieldValueFactorDescriptor < T > _FieldValueFactor { get ; set ; }
351+
352+ public FieldValueFactor ( Action < FieldValueFactorDescriptor < T > > descriptorBuilder )
353+ {
354+ var descriptor = new FieldValueFactorDescriptor < T > ( ) ;
355+ descriptorBuilder ( descriptor ) ;
356+
357+ this . _FieldValueFactor = descriptor ;
358+ }
359+ }
360+
361+ public enum FieldValueFactorModifier
362+ {
363+ none ,
364+ log ,
365+ log1p ,
366+ log2p ,
367+ ln ,
368+ ln1p ,
369+ ln2p ,
370+ square ,
371+ sqrt ,
372+ reciprocal
373+ }
374+
375+ [ JsonObject ( MemberSerialization = MemberSerialization . OptIn ) ]
309376 public class ScriptScoreFunction < T > : FunctionScoreFilteredFunction < T > where T : class
310377 {
311378 [ JsonProperty ( PropertyName = "script_score" ) ]
0 commit comments