Skip to content

Commit 510865f

Browse files
authored
Return overloads that do not take format on Field in 6.x, (#3543)
* Return overloads that do not take format on Field in 6.x, removing them was a bwc breaking change * Remove ambiguity on Field constructor and Field static methods on Infer * Fixed overload of Field on static infer still being nullable, and chain methods And on Field * string overload on field constructor needed fixing too
1 parent 1c5fea6 commit 510865f

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/Nest/CommonAbstractions/Infer/Field/Field.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public class Field : IEquatable<Field>, IUrlParameter
1818
private readonly object _comparisonValue;
1919
private readonly Type _type;
2020

21-
public Field(string name, double? boost = null, string format = null)
21+
public Field(string name, double? boost = null) : this(name, boost, format: null) {}
22+
23+
public Field(string name, double? boost, string format = null)
2224
{
2325
name.ThrowIfNullOrEmpty(nameof(name));
2426
Name = ParseFieldName(name, out var b);
@@ -27,7 +29,9 @@ public Field(string name, double? boost = null, string format = null)
2729
_comparisonValue = Name;
2830
}
2931

30-
public Field(Expression expression, double? boost = null, string format = null)
32+
public Field(Expression expression, double? boost = null) : this(expression, boost, format: null) { }
33+
34+
public Field(Expression expression, double? boost, string format = null)
3135
{
3236
Expression = expression ?? throw new ArgumentNullException(nameof(expression));
3337
Boost = boost;
@@ -37,7 +41,9 @@ public Field(Expression expression, double? boost = null, string format = null)
3741
CachableExpression = !new HasVariableExpressionVisitor(expression).Found;
3842
}
3943

40-
public Field(PropertyInfo property, double? boost = null, string format = null)
44+
public Field(PropertyInfo property, double? boost = null) : this(property, boost, format: null) { }
45+
46+
public Field(PropertyInfo property, double? boost, string format = null)
4147
{
4248
Property = property ?? throw new ArgumentNullException(nameof(property));
4349
Boost = boost;
@@ -98,13 +104,21 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings)
98104

99105
public Fields And(Field field) => new Fields(new[] { this, field });
100106

101-
public Fields And<T>(Expression<Func<T, object>> field, double? boost = null, string format = null) where T : class =>
107+
public Fields And<T>(Expression<Func<T, object>> field, double? boost = null) where T : class =>
108+
new Fields(new[] { this, new Field(field, boost, format: null) });
109+
110+
public Fields And<T>(Expression<Func<T, object>> field, double? boost, string format = null) where T : class =>
102111
new Fields(new[] { this, new Field(field, boost, format) });
103112

104-
public Fields And(string field, double? boost = null, string format = null) =>
113+
public Fields And(string field, double? boost = null) => new Fields(new[] { this, new Field(field, boost, format: null) });
114+
115+
public Fields And(string field, double? boost, string format = null) =>
105116
new Fields(new[] { this, new Field(field, boost, format) });
106117

107-
public Fields And(PropertyInfo property, double? boost = null, string format = null) =>
118+
public Fields And(PropertyInfo property, double? boost = null) =>
119+
new Fields(new[] { this, new Field(property, boost, format: null) });
120+
121+
public Fields And(PropertyInfo property, double? boost, string format = null) =>
108122
new Fields(new[] { this, new Field(property, boost, format) });
109123

110124
private static string ParseFieldName(string name, out double? boost)

src/Nest/CommonAbstractions/Static/Infer.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ public static Fields Fields<T>(params Expression<Func<T, object>>[] fields) wher
5656
/// Create a strongly typed string field name representation of the path to a property
5757
/// <para>e.g. p => p.Array.First().SubProperty.Field will return 'array.subProperty.field'</para>
5858
/// </summary>
59-
public static Field Field<T>(Expression<Func<T, object>> path, double? boost = null, string format = null)
59+
public static Field Field<T>(Expression<Func<T, object>> path, double? boost = null) where T : class => Field(path, boost, null);
60+
61+
public static Field Field<T>(Expression<Func<T, object>> path, double? boost, string format = null)
6062
where T : class => new Field(path, boost, format);
6163

62-
public static Field Field(string field, double? boost = null, string format = null) =>
63-
new Field(field, boost, format);
64+
public static Field Field(string field, double? boost = null) => Field(field, boost, format: null);
65+
66+
public static Field Field(string field, double? boost, string format = null) => new Field(field, boost, format);
6467

65-
public static Field Field(PropertyInfo property, double? boost = null, string format = null) =>
68+
public static Field Field(PropertyInfo property, double? boost = null) => Field(property, boost, format: null);
69+
public static Field Field(PropertyInfo property, double? boost, string format = null) =>
6670
new Field(property, boost, format);
6771

6872
public static PropertyName Property(string property) => property;

src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public void PrecedenceIsAsExpected()
500500
usingSettings.Expect("data").ForField(Field<Precedence>(p => p.DataMember));
501501
usingSettings.Expect("DEFAULTFIELDNAMEINFERRER").ForField(Field<Precedence>(p => p.DefaultFieldNameInferrer));
502502

503-
503+
var x = Field<Project>(p => p.Name, 1.0);
504504
/** The same naming rules also apply when indexing a document */
505505
usingSettings.Expect(new []
506506
{

src/Tests/Tests/Search/Search/SearchApiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ public SearchApiDocValueFieldsTests(ReadOnlyCluster cluster, EndpointUsage usage
272272
Field = "state",
273273
Value = "Stable"
274274
}),
275-
DocValueFields = Infer.Field<Project>(p => p.Name, format: "use_field_mapping")
276-
.And<Project>(p => p.LastActivity, format: "weekyear")
275+
DocValueFields = Infer.Field<Project>(p => p.Name, boost: null, format: "use_field_mapping")
276+
.And<Project>(p => p.LastActivity, boost: null, format: "weekyear")
277277
};
278278

279279
protected override void ExpectResponse(ISearchResponse<Project> response)

0 commit comments

Comments
 (0)