|
| 1 | +using System.Diagnostics; |
| 2 | +using System.Runtime.Serialization; |
| 3 | +using Elasticsearch.Net.Utf8Json; |
| 4 | + |
| 5 | +namespace Nest |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Maps a property as a shape field |
| 9 | + /// </summary> |
| 10 | + [InterfaceDataContract] |
| 11 | + public interface IShapeProperty : IDocValuesProperty |
| 12 | + { |
| 13 | + /// <summary> |
| 14 | + /// If <c>true</c>, malformed geojson shapes are ignored. If false (default), |
| 15 | + /// malformed geojson shapes throw an exception and reject the whole document. |
| 16 | + /// </summary> |
| 17 | + [DataMember(Name ="ignore_malformed")] |
| 18 | + bool? IgnoreMalformed { get; set; } |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// If true (default) three dimension points will be accepted (stored in source) but |
| 22 | + /// only latitude and longitude values will be indexed; the third dimension is ignored. If false, |
| 23 | + /// geo-points containing any more than latitude and longitude (two dimensions) values throw |
| 24 | + /// an exception and reject the whole document. |
| 25 | + /// </summary> |
| 26 | + [DataMember(Name ="ignore_z_value")] |
| 27 | + bool? IgnoreZValue { get; set; } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Defines how to interpret vertex order for polygons and multipolygons. |
| 31 | + /// Defaults to <see cref="ShapeOrientation.CounterClockWise" /> |
| 32 | + /// </summary> |
| 33 | + [DataMember(Name ="orientation")] |
| 34 | + ShapeOrientation? Orientation { get; set; } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Should the data be coerced into becoming a valid geo shape (for instance closing a polygon) |
| 38 | + /// </summary> |
| 39 | + [DataMember(Name ="coerce")] |
| 40 | + bool? Coerce { get; set; } |
| 41 | + } |
| 42 | + |
| 43 | + /// <inheritdoc cref="IShapeProperty" /> |
| 44 | + [DebuggerDisplay("{DebugDisplay}")] |
| 45 | + public class ShapeProperty : DocValuesPropertyBase, IShapeProperty |
| 46 | + { |
| 47 | + public ShapeProperty() : base(FieldType.Shape) { } |
| 48 | + |
| 49 | + /// <inheritdoc /> |
| 50 | + public bool? IgnoreMalformed { get; set; } |
| 51 | + |
| 52 | + /// <inheritdoc /> |
| 53 | + public bool? IgnoreZValue { get; set; } |
| 54 | + |
| 55 | + /// <inheritdoc /> |
| 56 | + public ShapeOrientation? Orientation { get; set; } |
| 57 | + |
| 58 | + /// <inheritdoc /> |
| 59 | + public bool? Coerce { get; set; } |
| 60 | + } |
| 61 | + |
| 62 | + /// <inheritdoc cref="IShapeProperty" /> |
| 63 | + [DebuggerDisplay("{DebugDisplay}")] |
| 64 | + public class ShapePropertyDescriptor<T> |
| 65 | + : DocValuesPropertyDescriptorBase<ShapePropertyDescriptor<T>, IShapeProperty, T>, IShapeProperty |
| 66 | + where T : class |
| 67 | + { |
| 68 | + public ShapePropertyDescriptor() : base(FieldType.Shape) { } |
| 69 | + |
| 70 | + bool? IShapeProperty.IgnoreMalformed { get; set; } |
| 71 | + bool? IShapeProperty.IgnoreZValue { get; set; } |
| 72 | + ShapeOrientation? IShapeProperty.Orientation { get; set; } |
| 73 | + bool? IShapeProperty.Coerce { get; set; } |
| 74 | + |
| 75 | + /// <inheritdoc cref="IShapeProperty.Orientation" /> |
| 76 | + public ShapePropertyDescriptor<T> Orientation(ShapeOrientation? orientation) => |
| 77 | + Assign(orientation, (a, v) => a.Orientation = v); |
| 78 | + |
| 79 | + /// <inheritdoc cref="IShapeProperty.IgnoreMalformed" /> |
| 80 | + public ShapePropertyDescriptor<T> IgnoreMalformed(bool? ignoreMalformed = true) => |
| 81 | + Assign(ignoreMalformed, (a, v) => a.IgnoreMalformed = v); |
| 82 | + |
| 83 | + /// <inheritdoc cref="IShapeProperty.IgnoreZValue" /> |
| 84 | + public ShapePropertyDescriptor<T> IgnoreZValue(bool? ignoreZValue = true) => |
| 85 | + Assign(ignoreZValue, (a, v) => a.IgnoreZValue = v); |
| 86 | + |
| 87 | + /// <inheritdoc cref="IShapeProperty.Coerce" /> |
| 88 | + public ShapePropertyDescriptor<T> Coerce(bool? coerce = true) => |
| 89 | + Assign(coerce, (a, v) => a.Coerce = v); |
| 90 | + } |
| 91 | +} |
0 commit comments