From 39d4e533fc561f9bf1f14503d4c98a11b71709c6 Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Mon, 14 Jan 2019 19:16:05 +0100 Subject: [PATCH 1/4] Return overloads that do not take format on Field in 6.x, removing them was a bwc breaking change --- src/Nest/CommonAbstractions/Infer/Field/Field.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Nest/CommonAbstractions/Infer/Field/Field.cs b/src/Nest/CommonAbstractions/Infer/Field/Field.cs index 2151d5e8149..bba4d1769ed 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/Field.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/Field.cs @@ -27,6 +27,8 @@ public Field(string name, double? boost = null, string format = null) _comparisonValue = Name; } + public Field(Expression expression, double? boost = null) : this(expression, boost, format: null) { } + public Field(Expression expression, double? boost = null, string format = null) { Expression = expression ?? throw new ArgumentNullException(nameof(expression)); @@ -37,6 +39,8 @@ public Field(Expression expression, double? boost = null, string format = null) CachableExpression = !new HasVariableExpressionVisitor(expression).Found; } + public Field(PropertyInfo property, double? boost = null) : this(property, boost, format: null) { } + public Field(PropertyInfo property, double? boost = null, string format = null) { Property = property ?? throw new ArgumentNullException(nameof(property)); From 854794535fda198559dbd349fcddd761de09ce94 Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Tue, 15 Jan 2019 08:35:54 +0100 Subject: [PATCH 2/4] Remove ambiguity on Field constructor and Field static methods on Infer --- src/Nest/CommonAbstractions/Infer/Field/Field.cs | 4 ++-- src/Nest/CommonAbstractions/Static/Infer.cs | 10 +++++++--- .../HighLevel/Inference/FieldInference.doc.cs | 2 +- src/Tests/Tests/Search/Search/SearchApiTests.cs | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Nest/CommonAbstractions/Infer/Field/Field.cs b/src/Nest/CommonAbstractions/Infer/Field/Field.cs index bba4d1769ed..80f27d47e4d 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/Field.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/Field.cs @@ -29,7 +29,7 @@ public Field(string name, double? boost = null, string format = null) public Field(Expression expression, double? boost = null) : this(expression, boost, format: null) { } - public Field(Expression expression, double? boost = null, string format = null) + public Field(Expression expression, double? boost, string format = null) { Expression = expression ?? throw new ArgumentNullException(nameof(expression)); Boost = boost; @@ -41,7 +41,7 @@ public Field(Expression expression, double? boost = null, string format = null) public Field(PropertyInfo property, double? boost = null) : this(property, boost, format: null) { } - public Field(PropertyInfo property, double? boost = null, string format = null) + public Field(PropertyInfo property, double? boost, string format = null) { Property = property ?? throw new ArgumentNullException(nameof(property)); Boost = boost; diff --git a/src/Nest/CommonAbstractions/Static/Infer.cs b/src/Nest/CommonAbstractions/Static/Infer.cs index ac612e179ff..92e5db72b67 100644 --- a/src/Nest/CommonAbstractions/Static/Infer.cs +++ b/src/Nest/CommonAbstractions/Static/Infer.cs @@ -56,12 +56,16 @@ public static Fields Fields(params Expression>[] fields) wher /// Create a strongly typed string field name representation of the path to a property /// e.g. p => p.Array.First().SubProperty.Field will return 'array.subProperty.field' /// - public static Field Field(Expression> path, double? boost = null, string format = null) + public static Field Field(Expression> path, double? boost = null) where T : class => Field(path, boost, null); + + public static Field Field(Expression> path, double? boost, string format = null) where T : class => new Field(path, boost, format); - public static Field Field(string field, double? boost = null, string format = null) => - new Field(field, boost, format); + public static Field Field(string field, double? boost = null) => Field(field, boost, format: null); + + public static Field Field(string field, double? boost, string format = null) => new Field(field, boost, format); + public static Field Field(PropertyInfo property, double? boost = null) => Field(property, boost, format: null); public static Field Field(PropertyInfo property, double? boost = null, string format = null) => new Field(property, boost, format); diff --git a/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs b/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs index 981ab70bca7..46577190797 100644 --- a/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs +++ b/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs @@ -500,7 +500,7 @@ public void PrecedenceIsAsExpected() usingSettings.Expect("data").ForField(Field(p => p.DataMember)); usingSettings.Expect("DEFAULTFIELDNAMEINFERRER").ForField(Field(p => p.DefaultFieldNameInferrer)); - + var x = Field(p => p.Name, 1.0); /** The same naming rules also apply when indexing a document */ usingSettings.Expect(new [] { diff --git a/src/Tests/Tests/Search/Search/SearchApiTests.cs b/src/Tests/Tests/Search/Search/SearchApiTests.cs index 1b6c5c6b444..5ce16bd992e 100644 --- a/src/Tests/Tests/Search/Search/SearchApiTests.cs +++ b/src/Tests/Tests/Search/Search/SearchApiTests.cs @@ -272,8 +272,8 @@ public SearchApiDocValueFieldsTests(ReadOnlyCluster cluster, EndpointUsage usage Field = "state", Value = "Stable" }), - DocValueFields = Infer.Field(p => p.Name, format: "use_field_mapping") - .And(p => p.LastActivity, format: "weekyear") + DocValueFields = Infer.Field(p => p.Name, boost: null, format: "use_field_mapping") + .And(p => p.LastActivity, boost: null, format: "weekyear") }; protected override void ExpectResponse(ISearchResponse response) From 4720d97a44133e2601cb5a488cb5076beab5aef1 Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Tue, 15 Jan 2019 08:58:32 +0100 Subject: [PATCH 3/4] Fixed overload of Field on static infer still being nullable, and chain methods And on Field --- src/Nest/CommonAbstractions/Infer/Field/Field.cs | 14 +++++++++++--- src/Nest/CommonAbstractions/Static/Infer.cs | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Nest/CommonAbstractions/Infer/Field/Field.cs b/src/Nest/CommonAbstractions/Infer/Field/Field.cs index 80f27d47e4d..1ed16c8be65 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/Field.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/Field.cs @@ -102,13 +102,21 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings) public Fields And(Field field) => new Fields(new[] { this, field }); - public Fields And(Expression> field, double? boost = null, string format = null) where T : class => + public Fields And(Expression> field, double? boost = null) where T : class => + new Fields(new[] { this, new Field(field, boost, format: null) }); + + public Fields And(Expression> field, double? boost, string format = null) where T : class => new Fields(new[] { this, new Field(field, boost, format) }); - public Fields And(string field, double? boost = null, string format = null) => + public Fields And(string field, double? boost = null) => new Fields(new[] { this, new Field(field, boost, format: null) }); + + public Fields And(string field, double? boost, string format = null) => new Fields(new[] { this, new Field(field, boost, format) }); - public Fields And(PropertyInfo property, double? boost = null, string format = null) => + public Fields And(PropertyInfo property, double? boost = null) => + new Fields(new[] { this, new Field(property, boost, format: null) }); + + public Fields And(PropertyInfo property, double? boost, string format = null) => new Fields(new[] { this, new Field(property, boost, format) }); private static string ParseFieldName(string name, out double? boost) diff --git a/src/Nest/CommonAbstractions/Static/Infer.cs b/src/Nest/CommonAbstractions/Static/Infer.cs index 92e5db72b67..588d226dd91 100644 --- a/src/Nest/CommonAbstractions/Static/Infer.cs +++ b/src/Nest/CommonAbstractions/Static/Infer.cs @@ -66,7 +66,7 @@ public static Field Field(Expression> path, double? boost, st public static Field Field(string field, double? boost, string format = null) => new Field(field, boost, format); public static Field Field(PropertyInfo property, double? boost = null) => Field(property, boost, format: null); - public static Field Field(PropertyInfo property, double? boost = null, string format = null) => + public static Field Field(PropertyInfo property, double? boost, string format = null) => new Field(property, boost, format); public static PropertyName Property(string property) => property; From fda63f78ca75c3d4900fd7bd6a9305e7a38422f0 Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Tue, 15 Jan 2019 09:22:34 +0100 Subject: [PATCH 4/4] string overload on field constructor needed fixing too --- src/Nest/CommonAbstractions/Infer/Field/Field.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Nest/CommonAbstractions/Infer/Field/Field.cs b/src/Nest/CommonAbstractions/Infer/Field/Field.cs index 1ed16c8be65..35f46c8f293 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/Field.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/Field.cs @@ -18,7 +18,9 @@ public class Field : IEquatable, IUrlParameter private readonly object _comparisonValue; private readonly Type _type; - public Field(string name, double? boost = null, string format = null) + public Field(string name, double? boost = null) : this(name, boost, format: null) {} + + public Field(string name, double? boost, string format = null) { name.ThrowIfNullOrEmpty(nameof(name)); Name = ParseFieldName(name, out var b);