Skip to content

Commit 1cd841b

Browse files
committed
maintain backwards compatibility for function_score query
1 parent 43dbc78 commit 1cd841b

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

src/Nest/DSL/Query/FunctionScoreQueryDescriptor.cs

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public interface IFunctionScoreQuery : IQuery
4040
[JsonProperty(PropertyName = "boost")]
4141
double? Boost { get; set; }
4242

43+
[Obsolete("random_score should be specified as a function within the functions of a function_score query", true)]
44+
IRandomScoreFunction RandomScore { get; set; }
45+
46+
[Obsolete("script_score should be specified as a function within the functions of a function_score query", true)]
47+
IScriptFilter ScriptScore { get; set; }
48+
49+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
50+
long? Weight { get; set; }
51+
52+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
53+
double? WeightAsDouble { get; set; }
4354
}
4455

4556
public class FunctionScoreQuery : PlainQuery, IFunctionScoreQuery
@@ -59,11 +70,30 @@ protected override void WrapInContainer(IQueryContainer container)
5970
public float? MaxBoost { get; set; }
6071
public double? Boost { get; set; }
6172
public float? MinScore { get; set; }
73+
74+
[Obsolete("random_score should be specified as a function within the functions of a function_score query", true)]
75+
public IRandomScoreFunction RandomScore { get; set; }
76+
77+
[Obsolete("script_score should be specified as a function within the functions of a function_score query", true)]
78+
public IScriptFilter ScriptScore { get; set; }
79+
80+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
81+
public long? Weight
82+
{
83+
get { return Convert.ToInt64(this.WeightAsDouble ); }
84+
set { this.WeightAsDouble = value; }
85+
}
86+
87+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
88+
public double? WeightAsDouble { get; set; }
6289
}
6390

6491
public class FunctionScoreQueryDescriptor<T> : IFunctionScoreQuery where T : class
6592
{
66-
private IFunctionScoreQuery Self { get { return this; }}
93+
private bool _forcedConditionless = false;
94+
private double? _weightAsDouble;
95+
96+
private IFunctionScoreQuery Self { get { return this; } }
6797

6898
IEnumerable<IFunctionScoreFunction> IFunctionScoreQuery.Functions { get; set; }
6999

@@ -83,15 +113,33 @@ public class FunctionScoreQueryDescriptor<T> : IFunctionScoreQuery where T : cla
83113

84114
string IQuery.Name { get; set; }
85115

86-
private bool _forcedConditionless = false;
116+
[Obsolete("random_score should be specified as a function within the functions of a function_score query", true)]
117+
IRandomScoreFunction IFunctionScoreQuery.RandomScore { get; set; }
118+
119+
[Obsolete("script_score should be specified as a function within the functions of a function_score query", true)]
120+
IScriptFilter IFunctionScoreQuery.ScriptScore { get; set; }
121+
122+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
123+
long? IFunctionScoreQuery.Weight
124+
{
125+
get { return Convert.ToInt64(_weightAsDouble); }
126+
set { _weightAsDouble = value; }
127+
}
128+
129+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
130+
double? IFunctionScoreQuery.WeightAsDouble
131+
{
132+
get { return _weightAsDouble; }
133+
set { _weightAsDouble = value; }
134+
}
87135

88136
bool IQuery.IsConditionless
89137
{
90138
get
91139
{
92140
return _forcedConditionless
93141
|| ((Self.Query == null || Self.Query.IsConditionless) && (Self.Filter == null || Self.Filter.IsConditionless)
94-
&& !Self.Functions.HasAny());
142+
&& !Self.Functions.HasAny());
95143
}
96144
}
97145

@@ -129,7 +177,7 @@ public FunctionScoreQueryDescriptor<T> Filter(Func<FilterDescriptor<T>, FilterCo
129177
var f = filterSelector(filter);
130178
Self.Filter = f.IsConditionless ? null : f;
131179
return this;
132-
}
180+
}
133181

134182
public FunctionScoreQueryDescriptor<T> Functions(params Func<FunctionScoreFunctionsDescriptor<T>, FunctionScoreFunction<T>>[] functions)
135183
{
@@ -174,5 +222,29 @@ public FunctionScoreQueryDescriptor<T> MinScore(float minScore)
174222
Self.MinScore = minScore;
175223
return this;
176224
}
225+
226+
[Obsolete("random_score should be specified as a function within the functions of a function_score query", true)]
227+
public FunctionScoreQueryDescriptor<T> RandomScore(int? seed = null)
228+
{
229+
return this;
230+
}
231+
232+
[Obsolete("script_score should be specified as a function within the functions of a function_score query", true)]
233+
public FunctionScoreQueryDescriptor<T> ScriptScore(Action<ScriptFilterDescriptor> scriptSelector)
234+
{
235+
return this;
236+
}
237+
238+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
239+
public FunctionScoreQueryDescriptor<T> Weight(double weight)
240+
{
241+
return this;
242+
}
243+
244+
[Obsolete("weight should be specified as a function within the functions of a function_score query", true)]
245+
public FunctionScoreQueryDescriptor<T> Weight(long weight)
246+
{
247+
return this;
248+
}
177249
}
178250
}

0 commit comments

Comments
 (0)