Skip to content

Commit cc1d34a

Browse files
committed
Tidy up
1 parent 106ce73 commit cc1d34a

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed

src/Nest/CommonOptions/Scripting/InlineScript.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ public interface IInlineScript : IScript
99
[JsonProperty("source")]
1010
string Source { get; set; }
1111

12-
[Obsolete("Inline is being deprecated for Source and will be removed in Elasticsearch 7.0")]
12+
[Obsolete("Use Source. Inline is deprecated and scheduled to be removed in Elasticsearch 7.0")]
1313
[JsonIgnore]
1414
string Inline { get; set; }
1515
}
1616

1717
public class InlineScript : ScriptBase, IInlineScript
1818
{
19-
public InlineScript(string script)
20-
{
21-
this.Source = script;
22-
}
19+
public InlineScript(string script) => this.Source = script;
2320

2421
public string Source { get; set; }
2522
public string Inline { get => this.Source; set => this.Source = value; }
@@ -33,15 +30,13 @@ public class InlineScriptDescriptor
3330
string IInlineScript.Inline { get => Self.Source; set => Self.Source = value; }
3431
string IInlineScript.Source { get; set; }
3532

36-
public InlineScriptDescriptor() {}
33+
public InlineScriptDescriptor() { }
3734

38-
public InlineScriptDescriptor(string script)
39-
{
40-
Self.Source = script;
41-
}
35+
public InlineScriptDescriptor(string script) => Self.Source = script;
4236

43-
[Obsolete("Inline is being deprecated for Source and will be removed in Elasticsearch 7.0")]
37+
[Obsolete("Use Source(). Inline() is deprecated and scheduled to be removed in Elasticsearch 7.0")]
4438
public InlineScriptDescriptor Inline(string script) => Assign(a => a.Source = script);
39+
4540
public InlineScriptDescriptor Source(string script) => Assign(a => a.Source = script);
4641
}
4742
}

src/Nest/CommonOptions/Scripting/ScriptBase.cs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using Elasticsearch.Net;
34
using Newtonsoft.Json;
45

56
namespace Nest
@@ -8,10 +9,26 @@ namespace Nest
89
[JsonConverter(typeof(ScriptJsonConverter))]
910
public interface IScript
1011
{
12+
/// <summary>
13+
/// Scripts are compiled and cached for faster execution.
14+
/// If the same script can be used, just with different parameters provided,
15+
/// it is preferable to use the ability to pass parameters to the script itself.
16+
/// </summary>
17+
/// <example>
18+
/// script: "doc['num1'].value &gt; param1"
19+
/// param: "param1" = 5
20+
/// </example>
21+
/// <param name="paramsDictionary">param</param>
22+
/// <returns>this</returns>
1123
[JsonProperty("params")]
1224
[JsonConverter(typeof(VerbatimDictionaryKeysPreservingNullJsonConverter<string, object>))]
1325
Dictionary<string, object> Params { get; set; }
1426

27+
/// <summary>
28+
/// Language of script.
29+
/// </summary>
30+
/// <param name="lang">language</param>
31+
/// <returns>this</returns>
1532
[JsonProperty("lang")]
1633
string Lang { get; set; }
1734
}
@@ -20,9 +37,17 @@ public abstract class ScriptBase : IScript
2037
{
2138
public Dictionary<string, object> Params { get; set; }
2239

40+
/// <summary>
41+
/// Language of script.
42+
/// </summary>
43+
/// <param name="lang">language</param>
44+
/// <returns>this</returns>
2345
public string Lang { get; set; }
2446

25-
public static implicit operator ScriptBase(string inline) => new InlineScript(inline);
47+
/// <summary>
48+
/// Implicit conversion from <see cref="string"/> to <see cref="InlineScript"/>
49+
/// </summary>
50+
public static implicit operator ScriptBase(string script) => new InlineScript(script);
2651
}
2752

2853
public abstract class ScriptDescriptorBase<TDescriptor, TInterface> : DescriptorBase<TDescriptor, TInterface>, IScript
@@ -32,22 +57,56 @@ public abstract class ScriptDescriptorBase<TDescriptor, TInterface> : Descriptor
3257
Dictionary<string, object> IScript.Params { get; set; }
3358
string IScript.Lang { get; set; }
3459

60+
/// <summary>
61+
/// Scripts are compiled and cached for faster execution.
62+
/// If the same script can be used, just with different parameters provided,
63+
/// it is preferable to use the ability to pass parameters to the script itself.
64+
/// </summary>
65+
/// <example>
66+
/// script: "doc['num1'].value &gt; param1"
67+
/// param: "param1" = 5
68+
/// </example>
69+
/// <param name="paramsDictionary">param</param>
70+
/// <returns>this</returns>
3571
public TDescriptor Params(Dictionary<string, object> scriptParams) => Assign(a => a.Params = scriptParams);
3672

37-
public TDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsSelector) =>
38-
Assign(a => a.Params = paramsSelector?.Invoke(new FluentDictionary<string, object>()));
73+
/// <summary>
74+
/// Scripts are compiled and cached for faster execution.
75+
/// If the same script can be used, just with different parameters provided,
76+
/// it is preferable to use the ability to pass parameters to the script itself.
77+
/// </summary>
78+
/// <example>
79+
/// script: "doc['num1'].value &gt; param1"
80+
/// param: "param1" = 5
81+
/// </example>
82+
/// <param name="paramsDictionary">param</param>
83+
/// <returns>this</returns>
84+
public TDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsDictionary) =>
85+
Assign(a => a.Params = paramsDictionary?.Invoke(new FluentDictionary<string, object>()));
3986

87+
/// <summary>
88+
/// Language of script.
89+
/// </summary>
90+
/// <param name="lang">language</param>
91+
/// <returns>this</returns>
4092
public TDescriptor Lang(string lang) => Assign(a => a.Lang = lang);
93+
94+
/// <summary>
95+
/// Language of script.
96+
/// </summary>
97+
/// <param name="lang">language</param>
98+
/// <returns>this</returns>
99+
public TDescriptor Lang(ScriptLang lang) => Assign(a => a.Lang = lang.GetStringValue());
41100
}
42101

43102
public class ScriptDescriptor : DescriptorBase<ScriptDescriptor, IDescriptor>
44103
{
45104
public IndexedScriptDescriptor Id(string id) => new IndexedScriptDescriptor(id);
46105

47-
[Obsolete("Indexed() sets a property named id, this is confusing and thats why we intent to remove this in NEST 7.x please use Id()")]
106+
[Obsolete("Use Id(). Indexed() sets a property named id, which is confusing. Will be removed in the next major version")]
48107
public IndexedScriptDescriptor Indexed(string id) => new IndexedScriptDescriptor(id);
49108

50-
[Obsolete("Inline is being deprecated for Source and will be removed in Elasticsearch 7.0")]
109+
[Obsolete("Use Source(). Inline() is deprecated and scheduled to be removed in Elasticsearch 7.0")]
51110
public InlineScriptDescriptor Inline(string script) => new InlineScriptDescriptor(script);
52111

53112
public InlineScriptDescriptor Source(string script) => new InlineScriptDescriptor(script);

src/Nest/QueryDsl/Specialized/Script/ScriptQuery.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
namespace Nest
77
{
8-
98
[JsonConverter(typeof(ScriptQueryConverter))]
109
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
1110
public interface IScriptQuery : IQuery
1211
{
1312
[JsonProperty("source")]
1413
string Source { get; set; }
1514

16-
[Obsolete("Inline is being deprecated for Source and will be removed in Elasticsearch 7.0")]
15+
[Obsolete("Use Source. Inline is deprecated and scheduled to be removed in Elasticsearch 7.0")]
1716
[JsonIgnore]
1817
string Inline { get; set; }
1918

@@ -32,7 +31,7 @@ public class ScriptQuery : QueryBase, IScriptQuery
3231
{
3332
protected override bool Conditionless => IsConditionless(this);
3433
public string Source { get; set; }
35-
[Obsolete("Inline is being deprecated for Source and will be removed in Elasticsearch 7.0")]
34+
[Obsolete("Use Source. Inline is deprecated and scheduled to be removed in Elasticsearch 7.0")]
3635
public string Inline { get => this.Source; set => this.Source = value; }
3736
public Id Id { get; set; }
3837
public Dictionary<string, object> Params { get; set; }
@@ -56,7 +55,7 @@ public class ScriptQueryDescriptor<T>
5655
Dictionary<string, object> IScriptQuery.Params { get; set; }
5756

5857
/// <summary> Inline script to execute </summary>
59-
[Obsolete("Inline is being deprecated for Source and will be removed in Elasticsearch 7.0")]
58+
[Obsolete("Use Source(). Inline() is deprecated and scheduled to be removed in Elasticsearch 7.0")]
6059
public ScriptQueryDescriptor<T> Inline(string script) => Assign(a => a.Inline = script);
6160

6261
/// <summary> Inline script to execute </summary>
@@ -74,10 +73,10 @@ public class ScriptQueryDescriptor<T>
7473
/// script: "doc['num1'].value &gt; param1"
7574
/// param: "param1" = 5
7675
/// </example>
77-
/// <param name="paramDictionary">param</param>
76+
/// <param name="paramsDictionary">param</param>
7877
/// <returns>this</returns>
79-
public ScriptQueryDescriptor<T> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramDictionary) =>
80-
Assign(a => a.Params = paramDictionary(new FluentDictionary<string, object>()));
78+
public ScriptQueryDescriptor<T> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsDictionary) =>
79+
Assign(a => a.Params = paramsDictionary?.Invoke(new FluentDictionary<string, object>()));
8180

8281
/// <summary>
8382
/// Language of script.

0 commit comments

Comments
 (0)