Skip to content

Commit

Permalink
Allow geo_shape types to be coerced into valid shapes. (#3718)
Browse files Browse the repository at this point in the history
* Allow geo_shape types to be coerced into valid shapes.
  • Loading branch information
Stuart Cam authored and russcam committed May 8, 2019
1 parent 707ee73 commit 17950ad
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
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

0 comments on commit 17950ad

Please sign in to comment.