Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow geo_shape types to be coerced into valid shapes. #3718

Merged
merged 2 commits into from
May 7, 2019
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
9 changes: 9 additions & 0 deletions src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public int TreeLevels
set => Self.TreeLevels = value;
}

/// <inheritdoc cref="IGeoShapeProperty.Coerce" />
public bool Coerce
{
get => Self.Coerce.GetValueOrDefault(true);
set => Self.Coerce = value;
}

double? IGeoShapeProperty.DistanceErrorPercentage { get; set; }
bool? IGeoShapeProperty.IgnoreMalformed { get; set; }
bool? IGeoShapeProperty.IgnoreZValue { get; set; }
Expand All @@ -74,5 +81,7 @@ public int TreeLevels

GeoTree? IGeoShapeProperty.Tree { get; set; }
int? IGeoShapeProperty.TreeLevels { get; set; }

bool? IGeoShapeProperty.Coerce { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public interface IGeoShapeProperty : IDocValuesProperty
/// </summary>
[JsonProperty("tree_levels")]
int? TreeLevels { get; set; }

/// <summary>
/// Should the data be coerced into becoming a valid geo shape (for instance closing a polygon)
/// </summary>
[JsonProperty("coerce")]
bool? Coerce { get; set; }
}

/// <inheritdoc cref="IGeoShapeProperty" />
Expand Down Expand Up @@ -131,6 +137,9 @@ public GeoShapeProperty() : base(FieldType.GeoShape) { }

/// <inheritdoc />
public int? TreeLevels { get; set; }

/// <inheritdoc />
public bool? Coerce { get; set; }
}

/// <inheritdoc cref="IGeoShapeProperty" />
Expand All @@ -151,6 +160,8 @@ public GeoShapePropertyDescriptor() : base(FieldType.GeoShape) { }
GeoTree? IGeoShapeProperty.Tree { get; set; }
int? IGeoShapeProperty.TreeLevels { get; set; }

bool? IGeoShapeProperty.Coerce { get; set; }

/// <inheritdoc cref="IGeoShapeProperty.Tree" />
public GeoShapePropertyDescriptor<T> Tree(GeoTree? tree) => Assign(tree, (a, v) => a.Tree = v);

Expand Down Expand Up @@ -181,5 +192,9 @@ public GeoShapePropertyDescriptor<T> IgnoreMalformed(bool? ignoreMalformed = tru
/// <inheritdoc cref="IGeoShapeProperty.IgnoreZValue" />
public GeoShapePropertyDescriptor<T> IgnoreZValue(bool? ignoreZValue = true) =>
Assign(ignoreZValue, (a, v) => a.IgnoreZValue = v);

/// <inheritdoc cref="IGeoShapeProperty.Coerce" />
public GeoShapePropertyDescriptor<T> Coerce(bool? coerce = true) =>
Assign(coerce, (a, v) => a.Coerce = v);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class GeoShapeTest
Strategy = GeoStrategy.Recursive,
TreeLevels = 3,
PointsOnly = true,
DistanceErrorPercentage = 1.0)]
DistanceErrorPercentage = 1.0,
Coerce = true)]
public object Full { get; set; }

[GeoShape]
Expand All @@ -31,7 +32,8 @@ public class GeoShapeAttributeTests : AttributeTestsBase<GeoShapeTest>
strategy = "recursive",
tree_levels = 3,
points_only = true,
distance_error_pct = 1.0
distance_error_pct = 1.0,
coerce = true
},
minimal = new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public GeoShapePropertyTests(WritableCluster cluster, EndpointUsage usage) : bas
strategy = "recursive",
tree_levels = 3,
points_only = true,
distance_error_pct = 1.0
distance_error_pct = 1.0,
coerce = true
}
}
};
Expand All @@ -36,6 +37,7 @@ public GeoShapePropertyTests(WritableCluster cluster, EndpointUsage usage) : bas
.TreeLevels(3)
.PointsOnly()
.DistanceErrorPercentage(1.0)
.Coerce()
);


Expand All @@ -49,7 +51,8 @@ public GeoShapePropertyTests(WritableCluster cluster, EndpointUsage usage) : bas
Strategy = GeoStrategy.Recursive,
TreeLevels = 3,
PointsOnly = true,
DistanceErrorPercentage = 1.0
DistanceErrorPercentage = 1.0,
Coerce = true
}
}
};
Expand Down