Skip to content

Commit 9d408a6

Browse files
committed
Move FieldValueFactor out of FunctionScoreFunctionsDescriptor to its own file
1 parent 0a0a7f6 commit 9d408a6

File tree

3 files changed

+59
-49
lines changed

3 files changed

+59
-49
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Converters;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Linq.Expressions;
7+
using System.Text;
8+
9+
namespace Nest
10+
{
11+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
12+
public class FieldValueFactor<T> : FunctionScoreFunction<T> where T : class
13+
{
14+
[JsonProperty(PropertyName = "field_value_factor")]
15+
internal FieldValueFactorDescriptor<T> _FieldValueFactor { get; set; }
16+
17+
public FieldValueFactor(Action<FieldValueFactorDescriptor<T>> descriptorBuilder)
18+
{
19+
var descriptor = new FieldValueFactorDescriptor<T>();
20+
descriptorBuilder(descriptor);
21+
if (descriptor._Field.IsConditionless())
22+
throw new DslException("Field name not set for field value factor function");
23+
24+
this._FieldValueFactor = descriptor;
25+
}
26+
}
27+
28+
public class FieldValueFactorDescriptor<T>
29+
{
30+
[JsonProperty("field")]
31+
internal PropertyPathMarker _Field { get; set; }
32+
33+
[JsonProperty("factor")]
34+
internal double? _Factor { get; set; }
35+
36+
[JsonProperty("modifier")]
37+
[JsonConverter(typeof(StringEnumConverter))]
38+
internal FieldValueFactorModifier? _Modifier { get; set; }
39+
40+
public FieldValueFactorDescriptor<T> Field(Expression<Func<T, object>> field)
41+
{
42+
this._Field = field;
43+
return this;
44+
}
45+
46+
public FieldValueFactorDescriptor<T> Factor(double factor)
47+
{
48+
this._Factor = factor;
49+
return this;
50+
}
51+
52+
public FieldValueFactorDescriptor<T> Modifier(FieldValueFactorModifier modifier)
53+
{
54+
this._Modifier = modifier;
55+
return this;
56+
}
57+
}
58+
}

src/Nest/DSL/Query/Functions/FunctionScoreFunctionsDescriptor.cs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -67,53 +67,4 @@ IEnumerator IEnumerable.GetEnumerator()
6767
return _Functions.GetEnumerator();
6868
}
6969
}
70-
71-
72-
public class FieldValueFactorDescriptor<T>
73-
{
74-
[JsonProperty("field")]
75-
internal PropertyPathMarker _Field { get; set; }
76-
77-
[JsonProperty("factor")]
78-
internal double? _Factor { get; set; }
79-
80-
[JsonProperty("modifier")]
81-
[JsonConverter(typeof (StringEnumConverter))]
82-
internal FieldValueFactorModifier? _Modifier { get; set; }
83-
84-
public FieldValueFactorDescriptor<T> Field(Expression<Func<T, object>> field)
85-
{
86-
this._Field = field;
87-
return this;
88-
}
89-
90-
public FieldValueFactorDescriptor<T> Factor(double factor)
91-
{
92-
this._Factor = factor;
93-
return this;
94-
}
95-
96-
public FieldValueFactorDescriptor<T> Modifier(FieldValueFactorModifier modifier)
97-
{
98-
this._Modifier = modifier;
99-
return this;
100-
}
101-
}
102-
103-
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
104-
public class FieldValueFactor<T> : FunctionScoreFunction<T> where T : class
105-
{
106-
[JsonProperty(PropertyName = "field_value_factor")]
107-
internal FieldValueFactorDescriptor<T> _FieldValueFactor { get; set; }
108-
109-
public FieldValueFactor(Action<FieldValueFactorDescriptor<T>> descriptorBuilder)
110-
{
111-
var descriptor = new FieldValueFactorDescriptor<T>();
112-
descriptorBuilder(descriptor);
113-
if (descriptor._Field.IsConditionless())
114-
throw new DslException("Field name not set for field value factor function");
115-
116-
this._FieldValueFactor = descriptor;
117-
}
118-
}
11970
}

src/Nest/Nest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
<Compile Include="DSL\Filter\GeoShapePolygonFilterDescriptor.cs" />
157157
<Compile Include="DSL\Filter\GeoShapePointFilterDescriptor.cs" />
158158
<Compile Include="DSL\GetAliasDescriptor.cs" />
159+
<Compile Include="DSL\Query\Functions\FieldValueFactorDescriptor.cs" />
159160
<Compile Include="DSL\Query\GeoShapeMultiPointQueryDescriptor.cs" />
160161
<Compile Include="DSL\Query\GeoShapeMultiPolygonQueryDescriptor.cs" />
161162
<Compile Include="DSL\Query\GeoShapePolygonQueryDescriptor.cs" />

0 commit comments

Comments
 (0)