Skip to content

Commit 91ef38d

Browse files
authored
Add backwards compatible overloads for Field format (#3548)
This commit adds backwards binary compatibility with 6.4.0 for method overloads on Field related types that can accept a format parameter.
1 parent a39ef5a commit 91ef38d

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public Fields And<T>(Expression<Func<T, object>> field, double? boost = null) wh
110110
public Fields And<T>(Expression<Func<T, object>> field, double? boost, string format = null) where T : class =>
111111
new Fields(new[] { this, new Field(field, boost, format) });
112112

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

115116
public Fields And(string field, double? boost, string format = null) =>
116117
new Fields(new[] { this, new Field(field, boost, format) });

src/Nest/CommonAbstractions/Infer/Fields/Fields.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,42 @@ public static implicit operator Fields(string field) => field.IsNullOrEmptyComma
5656

5757
public static implicit operator Fields(Field[] fields) => fields.IsEmpty() ? null : new Fields(fields);
5858

59-
public Fields And<T>(Expression<Func<T, object>> field, double? boost = null, string format = null) where T : class
59+
public Fields And<T>(Expression<Func<T, object>> field, double? boost, string format = null) where T : class
6060
{
6161
ListOfFields.Add(new Field(field, boost, format));
6262
return this;
6363
}
6464

65-
public Fields And(string field, double? boost = null, string format = null)
65+
public Fields And<T>(Expression<Func<T, object>> field, double? boost = null) where T : class
66+
{
67+
ListOfFields.Add(new Field(field, boost));
68+
return this;
69+
}
70+
71+
public Fields And(string field, double? boost, string format = null)
6672
{
6773
ListOfFields.Add(new Field(field, boost, format));
6874
return this;
6975
}
7076

77+
public Fields And(string field, double? boost = null)
78+
{
79+
ListOfFields.Add(new Field(field, boost));
80+
return this;
81+
}
82+
7183
public Fields And(PropertyInfo property, double? boost = null)
7284
{
7385
ListOfFields.Add(new Field(property, boost));
7486
return this;
7587
}
7688

89+
public Fields And(PropertyInfo property, double? boost, string format = null)
90+
{
91+
ListOfFields.Add(new Field(property, boost, format));
92+
return this;
93+
}
94+
7795
public Fields And<T>(params Expression<Func<T, object>>[] fields) where T : class
7896
{
7997
ListOfFields.AddRange(fields.Select(f => new Field(f)));

src/Nest/CommonAbstractions/Infer/Fields/FieldsDescriptor.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ public FieldsDescriptor() : base(new Fields()) { }
1515

1616
public FieldsDescriptor<T> Fields(IEnumerable<Field> fields) => Assign(f => f.ListOfFields.AddRange(fields));
1717

18-
public FieldsDescriptor<T> Field(Expression<Func<T, object>> field, double? boost = null, string format = null) =>
18+
public FieldsDescriptor<T> Field(Expression<Func<T, object>> field, double? boost, string format = null) =>
1919
Assign(f => f.And(field, boost, format));
2020

21-
public FieldsDescriptor<T> Field(string field, double? boost = null, string format = null) =>
21+
public FieldsDescriptor<T> Field(Expression<Func<T, object>> field, double? boost = null) =>
22+
Assign(f => f.And(field, boost));
23+
24+
public FieldsDescriptor<T> Field(string field, double? boost, string format = null) =>
2225
Assign(f => f.And(field, boost, format));
2326

27+
public FieldsDescriptor<T> Field(string field, double? boost = null) =>
28+
Assign(f => f.And(field, boost));
29+
2430
public FieldsDescriptor<T> Field(Field field) => Assign(f => f.And(field));
2531
}
2632
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ public SearchApiDocValueFieldsTests(ReadOnlyCluster cluster, EndpointUsage usage
254254
.Term(p => p.State, StateOfBeing.Stable)
255255
)
256256
.DocValueFields(fs => fs
257-
.Field(p => p.Name, format: "use_field_mapping")
258-
.Field(p => p.LastActivity, format: "weekyear")
257+
.Field(p => p.Name, null, format: "use_field_mapping")
258+
.Field(p => p.LastActivity, null, format: "weekyear")
259259
);
260260

261261
protected override SearchRequest<Project> Initializer => new SearchRequest<Project>()

0 commit comments

Comments
 (0)