Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/Nest/CommonAbstractions/Infer/Field/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class Field : IEquatable<Field>, 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);
Expand All @@ -27,7 +29,9 @@ public Field(string name, double? boost = null, string format = null)
_comparisonValue = Name;
}

public Field(Expression expression, double? boost = null, string format = null)
public Field(Expression expression, double? boost = null) : this(expression, boost, format: null) { }

public Field(Expression expression, double? boost, string format = null)
{
Expression = expression ?? throw new ArgumentNullException(nameof(expression));
Boost = boost;
Expand All @@ -37,7 +41,9 @@ public Field(Expression expression, double? boost = null, string format = null)
CachableExpression = !new HasVariableExpressionVisitor(expression).Found;
}

public Field(PropertyInfo property, double? boost = null, string format = null)
public Field(PropertyInfo property, double? boost = null) : this(property, boost, format: null) { }

public Field(PropertyInfo property, double? boost, string format = null)
{
Property = property ?? throw new ArgumentNullException(nameof(property));
Boost = boost;
Expand Down Expand Up @@ -98,13 +104,21 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings)

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

public Fields And<T>(Expression<Func<T, object>> field, double? boost = null, string format = null) where T : class =>
public Fields And<T>(Expression<Func<T, object>> field, double? boost = null) where T : class =>
new Fields(new[] { this, new Field(field, boost, format: null) });

public Fields And<T>(Expression<Func<T, object>> 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)
Expand Down
12 changes: 8 additions & 4 deletions src/Nest/CommonAbstractions/Static/Infer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ public static Fields Fields<T>(params Expression<Func<T, object>>[] fields) wher
/// Create a strongly typed string field name representation of the path to a property
/// <para>e.g. p => p.Array.First().SubProperty.Field will return 'array.subProperty.field'</para>
/// </summary>
public static Field Field<T>(Expression<Func<T, object>> path, double? boost = null, string format = null)
public static Field Field<T>(Expression<Func<T, object>> path, double? boost = null) where T : class => Field(path, boost, null);

public static Field Field<T>(Expression<Func<T, object>> 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, string format = null) =>
public static Field Field(PropertyInfo property, double? boost = null) => Field(property, boost, 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public void PrecedenceIsAsExpected()
usingSettings.Expect("data").ForField(Field<Precedence>(p => p.DataMember));
usingSettings.Expect("DEFAULTFIELDNAMEINFERRER").ForField(Field<Precedence>(p => p.DefaultFieldNameInferrer));


var x = Field<Project>(p => p.Name, 1.0);
/** The same naming rules also apply when indexing a document */
usingSettings.Expect(new []
{
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/Tests/Search/Search/SearchApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ public SearchApiDocValueFieldsTests(ReadOnlyCluster cluster, EndpointUsage usage
Field = "state",
Value = "Stable"
}),
DocValueFields = Infer.Field<Project>(p => p.Name, format: "use_field_mapping")
.And<Project>(p => p.LastActivity, format: "weekyear")
DocValueFields = Infer.Field<Project>(p => p.Name, boost: null, format: "use_field_mapping")
.And<Project>(p => p.LastActivity, boost: null, format: "weekyear")
};

protected override void ExpectResponse(ISearchResponse<Project> response)
Expand Down