diff --git a/src/Nest/DSL/Filter/FilterDescriptor.cs b/src/Nest/DSL/Filter/FilterDescriptor.cs index 7b5210fca78..f01046e4266 100644 --- a/src/Nest/DSL/Filter/FilterDescriptor.cs +++ b/src/Nest/DSL/Filter/FilterDescriptor.cs @@ -257,26 +257,202 @@ private FilterContainer _GeoDistanceRange(PropertyPathMarker field, Action - /// Filter documents indexed using the geo_shape type. + /// Filter documents indexed using the circle geo_shape type. /// - public FilterContainer GeoShape(Expression> fieldDescriptor, Action filterDescriptor) + public FilterContainer GeoShapeCircle(Expression> fieldDescriptor, Action filterDescriptor) { - return _GeoShape(fieldDescriptor, filterDescriptor); + return _GeoShapeCircle(fieldDescriptor, filterDescriptor); } /// - /// Filter documents indexed using the geo_shape type. + /// Filter documents indexed using the circle geo_shape type. + /// + public FilterContainer GeoShapeCircle(string field, Action filterDescriptor) + { + return _GeoShapeCircle(field, filterDescriptor); + } + + private FilterContainer _GeoShapeCircle(PropertyPathMarker field, Action filterDescriptor) + { + var filter = new GeoShapeCircleFilterDescriptor(); + if (filterDescriptor != null) + filterDescriptor(filter); + ((IGeoShapeCircleFilter)filter).Field = field; + return this.New(filter, f => f.GeoShape = filter); + } + + /// + /// Filter documents indexed using the envelope geo_shape type. + /// + public FilterContainer GeoShapeEnvelope(Expression> fieldDescriptor, Action filterDescriptor) + { + return _GeoShapeEnvelope(fieldDescriptor, filterDescriptor); + } + + /// + /// Filter documents indexed using the envelope geo_shape type. + /// + public FilterContainer GeoShapeEnvelope(string field, Action filterDescriptor) + { + return _GeoShapeEnvelope(field, filterDescriptor); + } + + private FilterContainer _GeoShapeEnvelope(PropertyPathMarker field, Action filterDescriptor) + { + var filter = new GeoShapeEnvelopeFilterDescriptor(); + if (filterDescriptor != null) + filterDescriptor(filter); + ((IGeoShapeEnvelopeFilter)filter).Field = field; + return this.New(filter, f => f.GeoShape = filter); + } + + /// + /// Filter documents indexed using the linestring geo_shape type. + /// + public FilterContainer GeoShapeLineString(Expression> fieldDescriptor, Action filterDescriptor) + { + return _GeoShapeLineString(fieldDescriptor, filterDescriptor); + } + + /// + /// Filter documents indexed using the linestring geo_shape type. + /// + public FilterContainer GeoShapeLineString(string field, Action filterDescriptor) + { + return _GeoShapeLineString(field, filterDescriptor); + } + + private FilterContainer _GeoShapeLineString(PropertyPathMarker field, Action filterDescriptor) + { + var filter = new GeoShapeLineStringFilterDescriptor(); + if (filterDescriptor != null) + filterDescriptor(filter); + ((IGeoShapeLineStringFilter)filter).Field = field; + return this.New(filter, f => f.GeoShape = filter); + } + + /// + /// Filter documents indexed using the multilinestring geo_shape type. + /// + public FilterContainer GeoShapeMultiLineString(Expression> fieldDescriptor, Action filterDescriptor) + { + return _GeoShapeMultiLineString(fieldDescriptor, filterDescriptor); + } + + /// + /// Filter documents indexed using the multilinestring geo_shape type. + /// + public FilterContainer GeoShapeMultiLineString(string field, Action filterDescriptor) + { + return _GeoShapeMultiLineString(field, filterDescriptor); + } + + private FilterContainer _GeoShapeMultiLineString(PropertyPathMarker field, Action filterDescriptor) + { + var filter = new GeoShapeMultiLineStringFilterDescriptor(); + if (filterDescriptor != null) + filterDescriptor(filter); + ((IGeoShapeMultiLineStringFilter)filter).Field = field; + return this.New(filter, f => f.GeoShape = filter); + } + + /// + /// Filter documents indexed using the point geo_shape type. + /// + public FilterContainer GeoShapePoint(Expression> fieldDescriptor, Action filterDescriptor) + { + return _GeoShapePoint(fieldDescriptor, filterDescriptor); + } + + /// + /// Filter documents indexed using the point geo_shape type. + /// + public FilterContainer GeoShapePoint(string field, Action filterDescriptor) + { + return _GeoShapePoint(field, filterDescriptor); + } + + private FilterContainer _GeoShapePoint(PropertyPathMarker field, Action filterDescriptor) + { + var filter = new GeoShapePointFilterDescriptor(); + if (filterDescriptor != null) + filterDescriptor(filter); + ((IGeoShapePointFilter)filter).Field = field; + return this.New(filter, f => f.GeoShape = filter); + } + + /// + /// Filter documents indexed using the multipoint geo_shape type. + /// + public FilterContainer GeoShapeMultiPoint(Expression> fieldDescriptor, Action filterDescriptor) + { + return _GeoShapeMultiPoint(fieldDescriptor, filterDescriptor); + } + + /// + /// Filter documents indexed using the multipoint geo_shape type. + /// + public FilterContainer GeoShapeMultiPoint(string field, Action filterDescriptor) + { + return _GeoShapeMultiPoint(field, filterDescriptor); + } + + private FilterContainer _GeoShapeMultiPoint(PropertyPathMarker field, Action filterDescriptor) + { + var filter = new GeoShapeMultiPointFilterDescriptor(); + if (filterDescriptor != null) + filterDescriptor(filter); + ((IGeoShapeMultiPointFilter)filter).Field = field; + return this.New(filter, f => f.GeoShape = filter); + } + + + /// + /// Filter documents indexed using the polygon geo_shape type. + /// + public FilterContainer GeoShapePolygon(Expression> fieldDescriptor, Action filterDescriptor) + { + return _GeoShapePolygon(fieldDescriptor, filterDescriptor); + } + + /// + /// Filter documents indexed using the polygon geo_shape type. + /// + public FilterContainer GeoShapePolygon(string field, Action filterDescriptor) + { + return _GeoShapePolygon(field, filterDescriptor); + } + + private FilterContainer _GeoShapePolygon(PropertyPathMarker field, Action filterDescriptor) + { + var filter = new GeoShapePolygonFilterDescriptor(); + if (filterDescriptor != null) + filterDescriptor(filter); + ((IGeoShapePolygonFilter)filter).Field = field; + return this.New(filter, f => f.GeoShape = filter); + } + + /// + /// Filter documents indexed using the multipolygon geo_shape type. + /// + public FilterContainer GeoShapeMultiPolygon(Expression> fieldDescriptor, Action filterDescriptor) + { + return _GeoShapeMultiPolygon(fieldDescriptor, filterDescriptor); + } + + /// + /// Filter documents indexed using the multipolygon geo_shape type. /// - public FilterContainer GeoShape(string field, Action filterDescriptor) + public FilterContainer GeoShapeMultiPolygon(string field, Action filterDescriptor) { - return _GeoShape(field, filterDescriptor); + return _GeoShapeMultiPolygon(field, filterDescriptor); } - private FilterContainer _GeoShape(PropertyPathMarker field, Action filterDescriptor) + private FilterContainer _GeoShapeMultiPolygon(PropertyPathMarker field, Action filterDescriptor) { - var filter = new GeoShapeFilterDescriptor(); + var filter = new GeoShapeMultiPolygonFilterDescriptor(); if (filterDescriptor != null) filterDescriptor(filter); - ((IGeoShapeFilter)filter).Field = field; + ((IGeoShapeMultiPolygonFilter)filter).Field = field; return this.New(filter, f => f.GeoShape = filter); } diff --git a/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs index a84385e2aae..531ccfb2eaf 100644 --- a/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs +++ b/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs @@ -11,7 +11,7 @@ public interface IGeoIndexedShapeFilter : IGeoShapeBaseFilter { [JsonProperty("indexed_shape")] - GeoIndexedShapeVector IndexedShape { get; set; } + IndexedGeoShape IndexedShape { get; set; } } public class GeoIndexedShapeFilter : PlainFilter, IGeoIndexedShapeFilter @@ -23,7 +23,7 @@ protected internal override void WrapInContainer(IFilterContainer container) public PropertyPathMarker Field { get; set; } - public GeoIndexedShapeVector IndexedShape { get; set; } + public IndexedGeoShape IndexedShape { get; set; } } public class GeoIndexedShapeFilterDescriptor : FilterBase, IGeoIndexedShapeFilter @@ -38,7 +38,7 @@ bool IFilter.IsConditionless } PropertyPathMarker IFieldNameFilter.Field { get; set; } - GeoIndexedShapeVector IGeoIndexedShapeFilter.IndexedShape { get; set; } + IndexedGeoShape IGeoIndexedShapeFilter.IndexedShape { get; set; } public GeoIndexedShapeFilterDescriptor Lookup(string field, string id, string index = null, string type = null) { @@ -47,7 +47,7 @@ public GeoIndexedShapeFilterDescriptor Lookup(string field, string id, string private GeoIndexedShapeFilterDescriptor _SetShape(PropertyPathMarker field, string id, string index, string type) { - ((IGeoIndexedShapeFilter)this).IndexedShape = new GeoIndexedShapeVector + ((IGeoIndexedShapeFilter)this).IndexedShape = new IndexedGeoShape { Field = field, Id = id, diff --git a/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs new file mode 100644 index 00000000000..1ef78fbb6a1 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeCircleFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + ICircleGeoShape Shape { get; set; } + } + + public class GeoShapeCircleFilter : PlainFilter, IGeoShapeCircleFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public ICircleGeoShape Shape { get; set; } + } + + public class GeoShapeCircleFilterDescriptor : FilterBase, IGeoShapeCircleFilter + { + IGeoShapeCircleFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + ICircleGeoShape IGeoShapeCircleFilter.Shape { get; set; } + + public GeoShapeCircleFilterDescriptor Coordinates(IEnumerable coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new CircleGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + + public GeoShapeCircleFilterDescriptor Radius(string radius) + { + if (this.Self.Shape == null) + this.Self.Shape = new CircleGeoShape(); + this.Self.Shape.Radius = radius; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/GeoShapeEnvelopeFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeEnvelopeFilterDescriptor.cs new file mode 100644 index 00000000000..c4da9c9d587 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapeEnvelopeFilterDescriptor.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeBaseFilter : IFieldNameFilter + { + } + + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeEnvelopeFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + IEnvelopeGeoShape Shape { get; set; } + } + + public class GeoShapeEnvelopeFilter : PlainFilter, IGeoShapeEnvelopeFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public IEnvelopeGeoShape Shape { get; set; } + } + + public class GeoShapeEnvelopeFilterDescriptor : FilterBase, IGeoShapeEnvelopeFilter + { + IGeoShapeEnvelopeFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + IEnvelopeGeoShape IGeoShapeEnvelopeFilter.Shape { get; set; } + + public GeoShapeEnvelopeFilterDescriptor Coordinates(IEnumerable> coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new EnvelopeGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs deleted file mode 100644 index d6ae8d73226..00000000000 --- a/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; - -namespace Nest -{ - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - public interface IGeoShapeBaseFilter : IFieldNameFilter - { - } - - public interface IGeoShapeFilter : IGeoShapeBaseFilter - { - [JsonProperty("shape")] - GeoShapeVector Shape { get; set; } - } - - public class GeoShapeFilter : PlainFilter, IGeoShapeFilter - { - protected internal override void WrapInContainer(IFilterContainer container) - { - container.GeoShape = this; - } - - public PropertyPathMarker Field { get; set; } - - public GeoShapeVector Shape { get; set; } - } - - public class GeoShapeFilterDescriptor : FilterBase, IGeoShapeFilter - { - bool IFilter.IsConditionless - { - get - { - return ((IGeoShapeFilter)this).Shape == null || !((IGeoShapeFilter)this).Shape.Coordinates.HasAny(); - } - } - - PropertyPathMarker IFieldNameFilter.Field { get; set; } - GeoShapeVector IGeoShapeFilter.Shape { get; set; } - - public GeoShapeFilterDescriptor Type(string type) - { - if (((IGeoShapeFilter)this).Shape == null) - ((IGeoShapeFilter)this).Shape = new GeoShapeVector(); - ((IGeoShapeFilter)this).Shape.Type = type; - return this; - } - - public GeoShapeFilterDescriptor Coordinates(IEnumerable> coordinates) - { - if (((IGeoShapeFilter)this).Shape == null) - ((IGeoShapeFilter)this).Shape = new GeoShapeVector(); - ((IGeoShapeFilter)this).Shape.Coordinates = coordinates; - return this; - } - - } - -} diff --git a/src/Nest/DSL/Filter/GeoShapeLineStringFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeLineStringFilterDescriptor.cs new file mode 100644 index 00000000000..7bdc9d75599 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapeLineStringFilterDescriptor.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeLineStringFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + ILineStringGeoShape Shape { get; set; } + } + + public class GeoShapeLineStringFilter : PlainFilter, IGeoShapeLineStringFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public ILineStringGeoShape Shape { get; set; } + } + + public class GeoShapeLineStringFilterDescriptor : FilterBase, IGeoShapeLineStringFilter + { + IGeoShapeLineStringFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + ILineStringGeoShape IGeoShapeLineStringFilter.Shape { get; set; } + + public GeoShapeLineStringFilterDescriptor Coordinates(IEnumerable> coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new LineStringGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/GeoShapeMultiLineStringFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeMultiLineStringFilterDescriptor.cs new file mode 100644 index 00000000000..b64c0bdfd21 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapeMultiLineStringFilterDescriptor.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeMultiLineStringFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + IMultiLineStringGeoShape Shape { get; set; } + } + + public class GeoShapeMultiLineStringFilter : PlainFilter, IGeoShapeMultiLineStringFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public IMultiLineStringGeoShape Shape { get; set; } + } + + public class GeoShapeMultiLineStringFilterDescriptor : FilterBase, IGeoShapeMultiLineStringFilter + { + IGeoShapeMultiLineStringFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + IMultiLineStringGeoShape IGeoShapeMultiLineStringFilter.Shape { get; set; } + + public GeoShapeMultiLineStringFilterDescriptor Coordinates(IEnumerable>> coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new MultiLineStringGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/GeoShapeMultiPointFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeMultiPointFilterDescriptor.cs new file mode 100644 index 00000000000..553c38c20e2 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapeMultiPointFilterDescriptor.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeMultiPointFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + IMultiPointGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPointFilter : PlainFilter, IGeoShapeMultiPointFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public IMultiPointGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPointFilterDescriptor : FilterBase, IGeoShapeMultiPointFilter + { + IGeoShapeMultiPointFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + IMultiPointGeoShape IGeoShapeMultiPointFilter.Shape { get; set; } + + public GeoShapeMultiPointFilterDescriptor Coordinates(IEnumerable> coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new MultiPointGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/GeoShapeMultiPolygonFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeMultiPolygonFilterDescriptor.cs new file mode 100644 index 00000000000..cad406f0d57 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapeMultiPolygonFilterDescriptor.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeMultiPolygonFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + IMultiPolygonGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPolygonFilter : PlainFilter, IGeoShapeMultiPolygonFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public IMultiPolygonGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPolygonFilterDescriptor : FilterBase, IGeoShapeMultiPolygonFilter + { + IGeoShapeMultiPolygonFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + IMultiPolygonGeoShape IGeoShapeMultiPolygonFilter.Shape { get; set; } + + public GeoShapeMultiPolygonFilterDescriptor Coordinates(IEnumerable>>> coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new MultiPolygonGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/GeoShapePointFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapePointFilterDescriptor.cs new file mode 100644 index 00000000000..70a69009796 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapePointFilterDescriptor.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapePointFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + IPointGeoShape Shape { get; set; } + } + + public class GeoShapePointFilter : PlainFilter, IGeoShapePointFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public IPointGeoShape Shape { get; set; } + } + + public class GeoShapePointFilterDescriptor : FilterBase, IGeoShapePointFilter + { + IGeoShapePointFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + IPointGeoShape IGeoShapePointFilter.Shape { get; set; } + + public GeoShapePointFilterDescriptor Coordinates(IEnumerable coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new PointGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/GeoShapePolygonFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapePolygonFilterDescriptor.cs new file mode 100644 index 00000000000..c66a47a526a --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapePolygonFilterDescriptor.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Nest.Resolvers; +using Nest.Resolvers.Converters; +using Nest.Resolvers.Converters.Filters; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapePolygonFilter : IGeoShapeBaseFilter + { + [JsonProperty("shape")] + IPolygonGeoShape Shape { get; set; } + } + + public class GeoShapePolygonFilter : PlainFilter, IGeoShapePolygonFilter + { + protected internal override void WrapInContainer(IFilterContainer container) + { + container.GeoShape = this; + } + + public PropertyPathMarker Field { get; set; } + + public IPolygonGeoShape Shape { get; set; } + } + + public class GeoShapePolygonFilterDescriptor : FilterBase, IGeoShapePolygonFilter + { + IGeoShapePolygonFilter Self { get { return this; } } + + bool IFilter.IsConditionless + { + get + { + return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny(); + } + } + + PropertyPathMarker IFieldNameFilter.Field { get; set; } + IPolygonGeoShape IGeoShapePolygonFilter.Shape { get; set; } + + public GeoShapePolygonFilterDescriptor Coordinates(IEnumerable>> coordinates) + { + if (this.Self.Shape == null) + this.Self.Shape = new PolygonGeoShape(); + this.Self.Shape.Coordinates = coordinates; + return this; + } + } + +} diff --git a/src/Nest/DSL/Filter/IFilterContainer.cs b/src/Nest/DSL/Filter/IFilterContainer.cs index a09dae45c47..c358dbc0fbc 100644 --- a/src/Nest/DSL/Filter/IFilterContainer.cs +++ b/src/Nest/DSL/Filter/IFilterContainer.cs @@ -59,7 +59,7 @@ public interface IFilterContainer IGeoPolygonFilter GeoPolygon { get; set; } [JsonProperty(PropertyName = "geo_shape")] - [JsonConverter(typeof(CompositeJsonConverter>))] + [JsonConverter(typeof(CompositeJsonConverter>))] IGeoShapeBaseFilter GeoShape { get; set; } [JsonProperty(PropertyName = "limit")] diff --git a/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeCircleQueryDescriptor.cs similarity index 50% rename from src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs rename to src/Nest/DSL/Query/GeoShapeCircleQueryDescriptor.cs index 49e147425c3..21501669a8d 100644 --- a/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs +++ b/src/Nest/DSL/Query/GeoShapeCircleQueryDescriptor.cs @@ -11,12 +11,16 @@ namespace Nest public interface IGeoShapeQuery : IFieldNameQuery { PropertyPathMarker Field { get; set; } + } + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeCircleQuery : IGeoShapeQuery + { [JsonProperty("shape")] - GeoShapeVector Shape { get; set; } + ICircleGeoShape Shape { get; set; } } - public class GeoShapeQuery : PlainQuery, IGeoShapeQuery + public class GeoShapeCircleQuery : PlainQuery, IGeoShapeCircleQuery { protected override void WrapInContainer(IQueryContainer container) { @@ -36,20 +40,21 @@ void IFieldNameQuery.SetFieldName(string fieldName) } public PropertyPathMarker Field { get; set; } - public GeoShapeVector Shape { get; set; } + + public ICircleGeoShape Shape { get; set; } } - public class GeoShapeQueryDescriptor : IGeoShapeQuery where T : class + public class GeoShapeCircleQueryDescriptor : IGeoShapeCircleQuery where T : class { PropertyPathMarker IGeoShapeQuery.Field { get; set; } - GeoShapeVector IGeoShapeQuery.Shape { get; set; } - + ICircleGeoShape IGeoShapeCircleQuery.Shape { get; set; } + bool IQuery.IsConditionless { get { - return ((IGeoShapeQuery)this).Field.IsConditionless() || (((IGeoShapeQuery)this).Shape == null || !((IGeoShapeQuery)this).Shape.Coordinates.HasAny()); + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapeCircleQuery)this).Shape == null || !((IGeoShapeCircleQuery)this).Shape.Coordinates.HasAny(); } } @@ -62,34 +67,32 @@ PropertyPathMarker IFieldNameQuery.GetFieldName() return ((IGeoShapeQuery)this).Field; } - public GeoShapeQueryDescriptor OnField(string field) + public GeoShapeCircleQueryDescriptor OnField(string field) { ((IGeoShapeQuery)this).Field = field; return this; } - public GeoShapeQueryDescriptor OnField(Expression> objectPath) + + public GeoShapeCircleQueryDescriptor OnField(Expression> objectPath) { ((IGeoShapeQuery)this).Field = objectPath; return this; } - - public GeoShapeQueryDescriptor Type(string type) + public GeoShapeCircleQueryDescriptor Coordinates(IEnumerable coordinates) { - if (((IGeoShapeQuery)this).Shape == null) - ((IGeoShapeQuery)this).Shape = new GeoShapeVector(); - ((IGeoShapeQuery)this).Shape.Type = type; + if (((IGeoShapeCircleQuery)this).Shape == null) + ((IGeoShapeCircleQuery)this).Shape = new CircleGeoShape(); + ((IGeoShapeCircleQuery)this).Shape.Coordinates = coordinates; return this; } - public GeoShapeQueryDescriptor Coordinates(IEnumerable> coordinates) + public GeoShapeCircleQueryDescriptor Radius(string radius) { - if (((IGeoShapeQuery)this).Shape == null) - ((IGeoShapeQuery)this).Shape = new GeoShapeVector(); - ((IGeoShapeQuery)this).Shape.Coordinates = coordinates; + if (((IGeoShapeCircleQuery)this).Shape == null) + ((IGeoShapeCircleQuery)this).Shape = new CircleGeoShape(); + ((IGeoShapeCircleQuery)this).Shape.Radius = radius; return this; } - } - } diff --git a/src/Nest/DSL/Query/GeoShapeEnvelopeQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeEnvelopeQueryDescriptor.cs new file mode 100644 index 00000000000..5b92574df92 --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapeEnvelopeQueryDescriptor.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using Nest.DSL.Query.Behaviour; +using Nest.Resolvers; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeEnvelopeQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + IEnvelopeGeoShape Shape { get; set; } + } + + public class GeoShapeEnvelopeQuery : PlainQuery, IGeoShapeEnvelopeQuery + { + protected override void WrapInContainer(IQueryContainer container) + { + container.GeoShape = this; + } + + bool IQuery.IsConditionless { get { return false; } } + + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return this.Field; + } + + void IFieldNameQuery.SetFieldName(string fieldName) + { + this.Field = fieldName; + } + + public PropertyPathMarker Field { get; set; } + + public IEnvelopeGeoShape Shape { get; set; } + } + + public class GeoShapeEnvelopeQueryDescriptor : IGeoShapeEnvelopeQuery where T : class + { + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + IEnvelopeGeoShape IGeoShapeEnvelopeQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapeEnvelopeQuery)this).Shape == null || !((IGeoShapeEnvelopeQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapeEnvelopeQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + + public GeoShapeEnvelopeQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapeEnvelopeQueryDescriptor Coordinates(IEnumerable> coordinates) + { + if (((IGeoShapeEnvelopeQuery)this).Shape == null) + ((IGeoShapeEnvelopeQuery)this).Shape = new EnvelopeGeoShape(); + ((IGeoShapeEnvelopeQuery)this).Shape.Coordinates = coordinates; + return this; + } + } +} diff --git a/src/Nest/DSL/Query/GeoShapeLineStringQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeLineStringQueryDescriptor.cs new file mode 100644 index 00000000000..2b2d8765e51 --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapeLineStringQueryDescriptor.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using Nest.DSL.Query.Behaviour; +using Nest.Resolvers; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeLineStringQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + ILineStringGeoShape Shape { get; set; } + } + + public class GeoShapeLineStringQuery : PlainQuery, IGeoShapeLineStringQuery + { + protected override void WrapInContainer(IQueryContainer container) + { + container.GeoShape = this; + } + + bool IQuery.IsConditionless { get { return false; } } + + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return this.Field; + } + + void IFieldNameQuery.SetFieldName(string fieldName) + { + this.Field = fieldName; + } + + public PropertyPathMarker Field { get; set; } + + public ILineStringGeoShape Shape { get; set; } + } + + public class GeoShapeLineStringQueryDescriptor : IGeoShapeLineStringQuery where T : class + { + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + ILineStringGeoShape IGeoShapeLineStringQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapeLineStringQuery)this).Shape == null || !((IGeoShapeLineStringQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapeLineStringQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + public GeoShapeLineStringQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapeLineStringQueryDescriptor Coordinates(IEnumerable> coordinates) + { + if (((IGeoShapeLineStringQuery)this).Shape == null) + ((IGeoShapeLineStringQuery)this).Shape = new LineStringGeoShape(); + ((IGeoShapeLineStringQuery)this).Shape.Coordinates = coordinates; + return this; + } + } +} diff --git a/src/Nest/DSL/Query/GeoShapeMultiLineStringQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeMultiLineStringQueryDescriptor.cs new file mode 100644 index 00000000000..8b635746216 --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapeMultiLineStringQueryDescriptor.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using Nest.DSL.Query.Behaviour; +using Nest.Resolvers; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeMultiLineStringQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + IMultiLineStringGeoShape Shape { get; set; } + } + + public class GeoShapeMultiLineStringQuery : PlainQuery, IGeoShapeMultiLineStringQuery + { + protected override void WrapInContainer(IQueryContainer container) + { + container.GeoShape = this; + } + + bool IQuery.IsConditionless { get { return false; } } + + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return this.Field; + } + + void IFieldNameQuery.SetFieldName(string fieldName) + { + this.Field = fieldName; + } + + public PropertyPathMarker Field { get; set; } + + public IMultiLineStringGeoShape Shape { get; set; } + } + + public class GeoShapeMultiLineStringQueryDescriptor : IGeoShapeMultiLineStringQuery where T : class + { + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + IMultiLineStringGeoShape IGeoShapeMultiLineStringQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapeMultiLineStringQuery)this).Shape == null || !((IGeoShapeMultiLineStringQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapeMultiLineStringQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + public GeoShapeMultiLineStringQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapeMultiLineStringQueryDescriptor Coordinates(IEnumerable>> coordinates) + { + if (((IGeoShapeMultiLineStringQuery)this).Shape == null) + ((IGeoShapeMultiLineStringQuery)this).Shape = new MultiLineStringGeoShape(); + ((IGeoShapeMultiLineStringQuery)this).Shape.Coordinates = coordinates; + return this; + } + } +} diff --git a/src/Nest/DSL/Query/GeoShapeMultiPointQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeMultiPointQueryDescriptor.cs new file mode 100644 index 00000000000..4c967f1f069 --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapeMultiPointQueryDescriptor.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using Nest.DSL.Query.Behaviour; +using Nest.Resolvers; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeMultiPointQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + IMultiPointGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPointQuery : PlainQuery, IGeoShapeMultiPointQuery + { + protected override void WrapInContainer(IQueryContainer container) + { + container.GeoShape = this; + } + + bool IQuery.IsConditionless { get { return false; } } + + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return this.Field; + } + + void IFieldNameQuery.SetFieldName(string fieldName) + { + this.Field = fieldName; + } + + public PropertyPathMarker Field { get; set; } + + public IMultiPointGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPointQueryDescriptor : IGeoShapeMultiPointQuery where T : class + { + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + IMultiPointGeoShape IGeoShapeMultiPointQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapeMultiPointQuery)this).Shape == null || !((IGeoShapeMultiPointQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapeMultiPointQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + public GeoShapeMultiPointQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapeMultiPointQueryDescriptor Coordinates(IEnumerable> coordinates) + { + if (((IGeoShapeMultiPointQuery)this).Shape == null) + ((IGeoShapeMultiPointQuery)this).Shape = new MultiPointGeoShape(); + ((IGeoShapeMultiPointQuery)this).Shape.Coordinates = coordinates; + return this; + } + } +} diff --git a/src/Nest/DSL/Query/GeoShapeMultiPolygonQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeMultiPolygonQueryDescriptor.cs new file mode 100644 index 00000000000..d005f93ceb4 --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapeMultiPolygonQueryDescriptor.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using Nest.DSL.Query.Behaviour; +using Nest.Resolvers; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeMultiPolygonQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + IMultiPolygonGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPolygonQuery : PlainQuery, IGeoShapeMultiPolygonQuery + { + protected override void WrapInContainer(IQueryContainer container) + { + container.GeoShape = this; + } + + bool IQuery.IsConditionless { get { return false; } } + + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return this.Field; + } + + void IFieldNameQuery.SetFieldName(string fieldName) + { + this.Field = fieldName; + } + + public PropertyPathMarker Field { get; set; } + + public IMultiPolygonGeoShape Shape { get; set; } + } + + public class GeoShapeMultiPolygonQueryDescriptor : IGeoShapeMultiPolygonQuery where T : class + { + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + IMultiPolygonGeoShape IGeoShapeMultiPolygonQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapeMultiPolygonQuery)this).Shape == null || !((IGeoShapeMultiPolygonQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapeMultiPolygonQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + public GeoShapeMultiPolygonQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapeMultiPolygonQueryDescriptor Coordinates(IEnumerable>>> coordinates) + { + if (((IGeoShapeMultiPolygonQuery)this).Shape == null) + ((IGeoShapeMultiPolygonQuery)this).Shape = new MultiPolygonGeoShape(); + ((IGeoShapeMultiPolygonQuery)this).Shape.Coordinates = coordinates; + return this; + } + } +} diff --git a/src/Nest/DSL/Query/GeoShapePointQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapePointQueryDescriptor.cs new file mode 100644 index 00000000000..eb09e37a245 --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapePointQueryDescriptor.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using Nest.DSL.Query.Behaviour; +using Nest.Resolvers; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapePointQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + IPointGeoShape Shape { get; set; } + } + + public class GeoShapePointQuery : PlainQuery, IGeoShapePointQuery + { + protected override void WrapInContainer(IQueryContainer container) + { + container.GeoShape = this; + } + + bool IQuery.IsConditionless { get { return false; } } + + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return this.Field; + } + + void IFieldNameQuery.SetFieldName(string fieldName) + { + this.Field = fieldName; + } + + public PropertyPathMarker Field { get; set; } + + public IPointGeoShape Shape { get; set; } + } + + public class GeoShapePointQueryDescriptor : IGeoShapePointQuery where T : class + { + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + IPointGeoShape IGeoShapePointQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapePointQuery)this).Shape == null || !((IGeoShapePointQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapePointQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + public GeoShapePointQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapePointQueryDescriptor Coordinates(IEnumerable coordinates) + { + if (((IGeoShapePointQuery)this).Shape == null) + ((IGeoShapePointQuery)this).Shape = new PointGeoShape(); + ((IGeoShapePointQuery)this).Shape.Coordinates = coordinates; + return this; + } + } +} diff --git a/src/Nest/DSL/Query/GeoShapePolygonQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapePolygonQueryDescriptor.cs new file mode 100644 index 00000000000..125ac938dad --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapePolygonQueryDescriptor.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using Nest.DSL.Query.Behaviour; +using Nest.Resolvers; +using Newtonsoft.Json; +using Elasticsearch.Net; + +namespace Nest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapePolygonQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + IPolygonGeoShape Shape { get; set; } + } + + public class GeoShapePolygonQuery : PlainQuery, IGeoShapePolygonQuery + { + protected override void WrapInContainer(IQueryContainer container) + { + container.GeoShape = this; + } + + bool IQuery.IsConditionless { get { return false; } } + + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return this.Field; + } + + void IFieldNameQuery.SetFieldName(string fieldName) + { + this.Field = fieldName; + } + + public PropertyPathMarker Field { get; set; } + + public IPolygonGeoShape Shape { get; set; } + } + + public class GeoShapePolygonQueryDescriptor : IGeoShapePolygonQuery where T : class + { + IGeoShapePolygonQuery Self { get { return this; } } + + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + IPolygonGeoShape IGeoShapePolygonQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapePolygonQuery)this).Shape == null || !((IGeoShapePolygonQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapePolygonQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + public GeoShapePolygonQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapePolygonQueryDescriptor Coordinates(IEnumerable>> coordinates) + { + if (((IGeoShapePolygonQuery)this).Shape == null) + ((IGeoShapePolygonQuery)this).Shape = new PolygonGeoShape(); + ((IGeoShapePolygonQuery)this).Shape.Coordinates = coordinates; + return this; + } + } +} diff --git a/src/Nest/DSL/Query/IQueryContainer.cs b/src/Nest/DSL/Query/IQueryContainer.cs index 5ed243eb1c0..c2d1e0175d3 100644 --- a/src/Nest/DSL/Query/IQueryContainer.cs +++ b/src/Nest/DSL/Query/IQueryContainer.cs @@ -27,15 +27,15 @@ public interface IQueryContainer : ICustomJson IMatchAllQuery MatchAllQuery { get; set; } [JsonProperty(PropertyName = "term")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof (FieldNameQueryConverter))] ITermQuery Term { get; set; } [JsonProperty(PropertyName = "wildcard")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof (FieldNameQueryConverter))] IWildcardQuery Wildcard { get; set; } [JsonProperty(PropertyName = "prefix")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof (FieldNameQueryConverter))] IPrefixQuery Prefix { get; set; } [JsonProperty(PropertyName = "boosting")] @@ -74,22 +74,22 @@ public interface IQueryContainer : ICustomJson IFuzzyQuery Fuzzy { get; set; } [JsonProperty(PropertyName = "geo_shape")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof(CompositeJsonConverter>))] IGeoShapeQuery GeoShape { get; set; } [JsonProperty(PropertyName = "common_terms")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof (FieldNameQueryConverter))] ICommonTermsQuery CommonTerms { get; set; } [JsonProperty(PropertyName = "terms")] ITermsQuery Terms { get; set; } [JsonProperty(PropertyName = "range")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof (FieldNameQueryConverter))] IRangeQuery Range { get; set; } [JsonProperty(PropertyName = "regexp")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof (FieldNameQueryConverter))] IRegexpQuery Regexp { get; set; } [JsonProperty(PropertyName = "has_child")] diff --git a/src/Nest/DSL/Query/QueryDescriptor.cs b/src/Nest/DSL/Query/QueryDescriptor.cs index 0e6c726efe7..c695c7d4780 100644 --- a/src/Nest/DSL/Query/QueryDescriptor.cs +++ b/src/Nest/DSL/Query/QueryDescriptor.cs @@ -312,16 +312,100 @@ public QueryContainer MoreLikeThis(Action> select /// /// The geo_shape Filter uses the same grid square representation as the geo_shape mapping to find documents - /// that have a shape that intersects with the query shape. + /// that have a shape that intersects with the envelope shape. /// It will also use the same PrefixTree configuration as defined for the field mapping. /// - public QueryContainer GeoShape(Action> selector) + public QueryContainer GeoShapeEnvelope(Action> selector) { - var query = new GeoShapeQueryDescriptor(); + var query = new GeoShapeEnvelopeQueryDescriptor(); selector(query); return this.New(query, q => q.GeoShape = query); } - + + /// + /// The geo_shape Filter uses the same grid square representation as the geo_shape mapping to find documents + /// that have a shape that intersects with the circle shape. + /// It will also use the same PrefixTree configuration as defined for the field mapping. + /// + public QueryContainer GeoShapeCircle(Action> selector) + { + var query = new GeoShapeCircleQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + /// + /// The geo_shape Filter uses the same grid square representation as the geo_shape mapping to find documents + /// that have a shape that intersects with the line string shape. + /// It will also use the same PrefixTree configuration as defined for the field mapping. + /// + public QueryContainer GeoShapeLineString(Action> selector) + { + var query = new GeoShapeLineStringQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + /// + /// The geo_shape circle Filter uses the same grid square representation as the geo_shape mapping to find documents + /// that have a shape that intersects with the multi line string shape. + /// It will also use the same PrefixTree configuration as defined for the field mapping. + /// + public QueryContainer GeoShapeMultiLineString(Action> selector) + { + var query = new GeoShapeMultiLineStringQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + /// + /// The geo_shape circle Filter uses the same grid square representation as the geo_shape mapping to find documents + /// that have a shape that intersects with the point shape. + /// It will also use the same PrefixTree configuration as defined for the field mapping. + /// + public QueryContainer GeoShapePoint(Action> selector) + { + var query = new GeoShapePointQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + /// + /// The geo_shape circle Filter uses the same grid square representation as the geo_shape mapping to find documents + /// that have a shape that intersects with the multi point shape. + /// It will also use the same PrefixTree configuration as defined for the field mapping. + /// + public QueryContainer GeoShapeMultiPoint(Action> selector) + { + var query = new GeoShapeMultiPointQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + /// + /// The geo_shape circle Filter uses the same grid square representation as the geo_shape mapping to find documents + /// that have a shape that intersects with the polygon shape. + /// It will also use the same PrefixTree configuration as defined for the field mapping. + /// + public QueryContainer GeoShapePolygon(Action> selector) + { + var query = new GeoShapePolygonQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + /// + /// The geo_shape circle Filter uses the same grid square representation as the geo_shape mapping to find documents + /// that have a shape that intersects with the multi polygon shape. + /// It will also use the same PrefixTree configuration as defined for the field mapping. + /// + public QueryContainer GeoShapeMultiPolygon(Action> selector) + { + var query = new GeoShapeMultiPolygonQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + /// /// The common terms query is a modern alternative to stopwords which improves the precision and recall /// of search results (by taking stopwords into account), without sacrificing performance. diff --git a/src/Nest/Domain/DSL/GeoShapeVector.cs b/src/Nest/Domain/DSL/GeoShapeVector.cs deleted file mode 100644 index d1bde12d361..00000000000 --- a/src/Nest/Domain/DSL/GeoShapeVector.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; - -namespace Nest -{ - /// - /// An object to describe a geoshape vetor - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html - /// - public class GeoShapeVector - { - [JsonProperty("type")] - public string Type { get; set; } - - [JsonProperty("coordinates")] - public IEnumerable> Coordinates { get; set; } - } -} diff --git a/src/Nest/Domain/DSL/Query.cs b/src/Nest/Domain/DSL/Query.cs index baae5038957..2ac1e47900f 100644 --- a/src/Nest/Domain/DSL/Query.cs +++ b/src/Nest/Domain/DSL/Query.cs @@ -133,9 +133,37 @@ public static QueryContainer CommonTerms(Action> s { return new QueryDescriptor().CommonTerms(selector); } - public static QueryContainer GeoShape(Action> selector) + public static QueryContainer GeoShapeCircle(Action> selector) { - return new QueryDescriptor().GeoShape(selector); + return new QueryDescriptor().GeoShapeCircle(selector); + } + public static QueryContainer GeoShapeEnvelope(Action> selector) + { + return new QueryDescriptor().GeoShapeEnvelope(selector); + } + public static QueryContainer GeoShapeLineString(Action> selector) + { + return new QueryDescriptor().GeoShapeLineString(selector); + } + public static QueryContainer GeoShapeMultiLineString(Action> selector) + { + return new QueryDescriptor().GeoShapeMultiLineString(selector); + } + public static QueryContainer GeoShapePoint(Action> selector) + { + return new QueryDescriptor().GeoShapePoint(selector); + } + public static QueryContainer GeoShapeMultiPoint(Action> selector) + { + return new QueryDescriptor().GeoShapeMultiPoint(selector); + } + public static QueryContainer GeoShapePolygon(Action> selector) + { + return new QueryDescriptor().GeoShapePolygon(selector); + } + public static QueryContainer GeoShapeMultiPolygon(Action> selector) + { + return new QueryDescriptor().GeoShapeMultiPolygon(selector); } public static QueryContainer QueryString(Action> selector) { diff --git a/src/Nest/Domain/Geometry/CircleGeoShape.cs b/src/Nest/Domain/Geometry/CircleGeoShape.cs new file mode 100644 index 00000000000..ad59d04a9a8 --- /dev/null +++ b/src/Nest/Domain/Geometry/CircleGeoShape.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface ICircleGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable Coordinates { get; set; } + + [JsonProperty("radius")] + string Radius { get; set; } + } + + public class CircleGeoShape : GeoShape, ICircleGeoShape + { + public CircleGeoShape() : this(null) { } + + public CircleGeoShape(IEnumerable coordinates) + : base("circle") + { + this.Coordinates = coordinates ?? new List(); + } + + public IEnumerable Coordinates { get; set; } + + public string Radius { get; set; } + } +} diff --git a/src/Nest/Domain/Geometry/EnvelopeGeoShape.cs b/src/Nest/Domain/Geometry/EnvelopeGeoShape.cs new file mode 100644 index 00000000000..a51316f9172 --- /dev/null +++ b/src/Nest/Domain/Geometry/EnvelopeGeoShape.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IEnvelopeGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable> Coordinates { get; set; } + } + + public class EnvelopeGeoShape : GeoShape, IEnvelopeGeoShape + { + public EnvelopeGeoShape() : this(null) { } + + public EnvelopeGeoShape(IEnumerable> coordinates) + : base("envelope") + { + this.Coordinates = coordinates ?? new List>(); + } + + public IEnumerable> Coordinates { get; set; } + } +} diff --git a/src/Nest/Domain/Geometry/GeoShape.cs b/src/Nest/Domain/Geometry/GeoShape.cs new file mode 100644 index 00000000000..556a661bcfb --- /dev/null +++ b/src/Nest/Domain/Geometry/GeoShape.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IGeoShape + { + [JsonProperty("type")] + string Type { get; } + } + + public abstract class GeoShape + { + public GeoShape(string type) + { + this.Type = type; + } + + public string Type { get; protected set; } + } +} diff --git a/src/Nest/Domain/DSL/GeoIndexedShapeVector.cs b/src/Nest/Domain/Geometry/IndexedGeoShape.cs similarity index 78% rename from src/Nest/Domain/DSL/GeoIndexedShapeVector.cs rename to src/Nest/Domain/Geometry/IndexedGeoShape.cs index d98989ff75f..8ad59953011 100644 --- a/src/Nest/Domain/DSL/GeoIndexedShapeVector.cs +++ b/src/Nest/Domain/Geometry/IndexedGeoShape.cs @@ -3,10 +3,10 @@ namespace Nest { /// - /// An object to describe a geoshape vetor + /// An object to describe an indexed geoshape /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html /// - public class GeoIndexedShapeVector + public class IndexedGeoShape { [JsonProperty("id")] public string Id { get; set; } @@ -17,7 +17,7 @@ public class GeoIndexedShapeVector [JsonProperty("index")] public IndexNameMarker Index { get; set; } - [JsonProperty("shape_field_name")] + [JsonProperty("path")] public PropertyPathMarker Field { get; set; } } } \ No newline at end of file diff --git a/src/Nest/Domain/Geometry/LineStringGeoShape.cs b/src/Nest/Domain/Geometry/LineStringGeoShape.cs new file mode 100644 index 00000000000..1b7b2293ef4 --- /dev/null +++ b/src/Nest/Domain/Geometry/LineStringGeoShape.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface ILineStringGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable> Coordinates { get; set; } + } + + public class LineStringGeoShape : GeoShape, ILineStringGeoShape + { + public LineStringGeoShape() : this(null) { } + + public LineStringGeoShape(IEnumerable> coordinates) + : base("linestring") + { + this.Coordinates = coordinates ?? new List>(); + } + + public IEnumerable> Coordinates { get; set; } + } +} diff --git a/src/Nest/Domain/Geometry/MultiLineStringGeoShape.cs b/src/Nest/Domain/Geometry/MultiLineStringGeoShape.cs new file mode 100644 index 00000000000..582078289d1 --- /dev/null +++ b/src/Nest/Domain/Geometry/MultiLineStringGeoShape.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IMultiLineStringGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable>> Coordinates { get; set; } + } + + public class MultiLineStringGeoShape : GeoShape, IMultiLineStringGeoShape + { + public MultiLineStringGeoShape() : this(null) { } + + public MultiLineStringGeoShape(IEnumerable>> coordinates) + : base("multilinestring") + { + this.Coordinates = coordinates ?? new List>>(); + } + + public IEnumerable>> Coordinates { get; set; } + } +} diff --git a/src/Nest/Domain/Geometry/MultiPointGeoShape.cs b/src/Nest/Domain/Geometry/MultiPointGeoShape.cs new file mode 100644 index 00000000000..0b9a817a6b3 --- /dev/null +++ b/src/Nest/Domain/Geometry/MultiPointGeoShape.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IMultiPointGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable> Coordinates { get; set; } + } + + public class MultiPointGeoShape : GeoShape, IMultiPointGeoShape + { + public MultiPointGeoShape() : this(null) { } + + public MultiPointGeoShape(IEnumerable> coordinates) + : base("multipoint") + { + this.Coordinates = coordinates ?? new List>(); + } + + public IEnumerable> Coordinates { get; set; } + } +} diff --git a/src/Nest/Domain/Geometry/MultiPolygonGeoShape.cs b/src/Nest/Domain/Geometry/MultiPolygonGeoShape.cs new file mode 100644 index 00000000000..855eabd4fad --- /dev/null +++ b/src/Nest/Domain/Geometry/MultiPolygonGeoShape.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IMultiPolygonGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable>>> Coordinates { get; set; } + } + + public class MultiPolygonGeoShape : GeoShape, IMultiPolygonGeoShape + { + public MultiPolygonGeoShape() : this(null) { } + + public MultiPolygonGeoShape(IEnumerable>>> coordinates) + : base("multipolygon") + { + this.Coordinates = coordinates ?? new List>>>(); + } + + public IEnumerable>>> Coordinates { get; set; } + } +} diff --git a/src/Nest/Domain/Geometry/PointGeoShape.cs b/src/Nest/Domain/Geometry/PointGeoShape.cs new file mode 100644 index 00000000000..7f9f4446e69 --- /dev/null +++ b/src/Nest/Domain/Geometry/PointGeoShape.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IPointGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable Coordinates { get; set; } + } + + public class PointGeoShape : GeoShape, IPointGeoShape + { + public PointGeoShape() : this(null) { } + + public PointGeoShape(IEnumerable coordinates) + : base("point") + { + this.Coordinates = coordinates ?? new List(); + } + + public IEnumerable Coordinates { get; set; } + } +} diff --git a/src/Nest/Domain/Geometry/PolygonGeoShape.cs b/src/Nest/Domain/Geometry/PolygonGeoShape.cs new file mode 100644 index 00000000000..3588c473832 --- /dev/null +++ b/src/Nest/Domain/Geometry/PolygonGeoShape.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IPolygonGeoShape : IGeoShape + { + [JsonProperty("coordinates")] + IEnumerable>> Coordinates { get; set; } + } + + public class PolygonGeoShape : GeoShape, IPolygonGeoShape + { + public PolygonGeoShape() : this(null) { } + + public PolygonGeoShape(IEnumerable>> coordinates) + : base("polygon") + { + this.Coordinates = coordinates ?? new List>>(); + } + + public IEnumerable>> Coordinates { get; set; } + } +} diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index f83ea2acba7..40ff8ffab38 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -137,8 +137,31 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -291,7 +314,7 @@ - + @@ -360,8 +383,7 @@ - - + @@ -374,7 +396,7 @@ - + @@ -656,6 +678,8 @@ + + diff --git a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs index 8812adebc79..c9c54486a82 100644 --- a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs +++ b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs @@ -6,7 +6,7 @@ namespace Nest.Resolvers.Converters.Filters { - public class GeoShapeFilterJsonReader : JsonConverter + public class GeoShapeFilterJsonReader : GeoShapeConverterBase { public override bool CanRead { get { return true; } } public override bool CanWrite { get { return false; } } @@ -47,25 +47,87 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var indexedShape = jv.Value["indexed_shape"]; if (shape != null) { - IGeoShapeFilter f = new GeoShapeFilterDescriptor(); - f.Shape = new GeoShapeVector(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); var type = shape["type"]; if (type != null) - f.Shape.Type = type.Value(); - filter = f; - break; + { + var typeName = type.Value(); + if (typeName == "circle") + { + IGeoShapeCircleFilter f = new GeoShapeCircleFilterDescriptor(); + f.Shape = new CircleGeoShape(); + f.Shape.Coordinates = GetCoordinates>(shape); + var radius = shape["radius"]; + if (radius != null) + f.Shape.Radius = radius.Value(); + filter = f; + break; + } + else if (typeName == "envelope") + { + IGeoShapeEnvelopeFilter f = new GeoShapeEnvelopeFilterDescriptor(); + f.Shape = new EnvelopeGeoShape(); + f.Shape.Coordinates = GetCoordinates>>(shape); + filter = f; + break; + } + else if (typeName == "linestring") + { + IGeoShapeLineStringFilter f = new GeoShapeLineStringFilterDescriptor(); + f.Shape = new LineStringGeoShape(); + f.Shape.Coordinates = GetCoordinates>>(shape); + filter = f; + break; + } + else if (typeName == "multilinestring") + { + IGeoShapeMultiLineStringFilter f = new GeoShapeMultiLineStringFilterDescriptor(); + f.Shape = new MultiLineStringGeoShape(); + f.Shape.Coordinates = GetCoordinates>>>(shape); + filter = f; + break; + } + else if (typeName == "point") + { + IGeoShapePointFilter f = new GeoShapePointFilterDescriptor(); + f.Shape = new PointGeoShape(); + f.Shape.Coordinates = GetCoordinates>(shape); + filter = f; + break; + } + else if (typeName == "multipoint") + { + IGeoShapeMultiPointFilter f = new GeoShapeMultiPointFilterDescriptor(); + f.Shape = new MultiPointGeoShape(); + f.Shape.Coordinates = GetCoordinates>>(shape); + filter = f; + break; + } + else if (typeName == "polygon") + { + IGeoShapePolygonFilter f = new GeoShapePolygonFilterDescriptor(); + f.Shape = new PolygonGeoShape(); + f.Shape.Coordinates = GetCoordinates>>>(shape); + filter = f; + break; + } + else if (typeName == "multipolygon") + { + IGeoShapeMultiPolygonFilter f = new GeoShapeMultiPolygonFilterDescriptor(); + f.Shape = new MultiPolygonGeoShape(); + f.Shape.Coordinates = GetCoordinates>>>>(shape); + filter = f; + break; + } + } } else if (indexedShape != null) { IGeoIndexedShapeFilter f = new GeoIndexedShapeFilterDescriptor(); - f.IndexedShape = new GeoIndexedShapeVector(); + f.IndexedShape = new IndexedGeoShape(); var id = indexedShape["id"]; var index = indexedShape["index"]; var type = indexedShape["type"]; - var shapeField = indexedShape["shape_field_name"]; + var shapeField = indexedShape["path"]; if (id != null) f.IndexedShape.Id = id.Value(); if (index != null) f.IndexedShape.Index = index.Value(); diff --git a/src/Nest/Resolvers/Converters/GeoShapeConverterBase.cs b/src/Nest/Resolvers/Converters/GeoShapeConverterBase.cs new file mode 100644 index 00000000000..92e8cf1b090 --- /dev/null +++ b/src/Nest/Resolvers/Converters/GeoShapeConverterBase.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest.Resolvers.Converters +{ + public abstract class GeoShapeConverterBase : JsonConverter + { + public virtual T GetCoordinates(JToken shape) + { + var coordinates = shape["coordinates"]; + if (coordinates != null) + return coordinates.ToObject(); + return default(T); + } + } +} diff --git a/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs new file mode 100644 index 00000000000..07b569a61e8 --- /dev/null +++ b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs @@ -0,0 +1,114 @@ +using Nest.Resolvers.Converters; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class GeoShapeQueryJsonReader : GeoShapeConverterBase + { + public override bool CanConvert(Type objectType) + { + return true; + } + public override bool CanRead { get { return true; } } + public override bool CanWrite { get { return false; } } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var j = JObject.Load(reader); + if (j == null || !j.HasValues) + return null; + + IGeoShapeQuery query = null; + + var firstProp = j.Properties().FirstOrDefault(); + if (firstProp == null) return null; + + var field = firstProp.Name; + var jo = firstProp.Value.Value(); + if (jo == null) return null; + + JToken shape; + jo.TryGetValue("shape", out shape); + + if (shape != null) + { + var type = shape["type"]; + if (type != null) + { + var typeName = type.Value(); + if (typeName == "circle") + { + IGeoShapeCircleQuery q = new GeoShapeCircleQueryDescriptor(); + q.Shape = new CircleGeoShape(); + q.Shape.Coordinates = GetCoordinates>(shape); + var radius = shape["radius"]; + if (radius != null) + q.Shape.Radius = radius.Value(); + query = q; + } + else if (typeName == "envelope") + { + IGeoShapeEnvelopeQuery q = new GeoShapeEnvelopeQueryDescriptor(); + q.Shape = new EnvelopeGeoShape(); + q.Shape.Coordinates = GetCoordinates>>(shape); + query = q; + } + else if (typeName == "linestring") + { + IGeoShapeLineStringQuery q = new GeoShapeLineStringQueryDescriptor(); + q.Shape = new LineStringGeoShape(); + q.Shape.Coordinates = GetCoordinates>>(shape); + query = q; + } + else if (typeName == "multilinestring") + { + IGeoShapeMultiLineStringQuery q = new GeoShapeMultiLineStringQueryDescriptor(); + q.Shape = new MultiLineStringGeoShape(); + q.Shape.Coordinates = GetCoordinates>>>(shape); + query = q; + } + else if (typeName == "point") + { + IGeoShapePointQuery q = new GeoShapePointQueryDescriptor(); + q.Shape = new PointGeoShape(); + q.Shape.Coordinates = GetCoordinates>(shape); + query = q; + } + else if (typeName == "multipoint") + { + IGeoShapeMultiPointQuery q = new GeoShapeMultiPointQueryDescriptor(); + q.Shape = new MultiPointGeoShape(); + q.Shape.Coordinates = GetCoordinates>>(shape); + query = q; + } + else if (typeName == "polygon") + { + IGeoShapePolygonQuery q = new GeoShapePolygonQueryDescriptor(); + q.Shape = new PolygonGeoShape(); + q.Shape.Coordinates = GetCoordinates>>>(shape); + query = q; + } + else if (typeName == "multipolygon") + { + IGeoShapeMultiPolygonQuery q = new GeoShapeMultiPolygonQueryDescriptor(); + q.Shape = new MultiPolygonGeoShape(); + q.Shape.Coordinates = GetCoordinates>>>>(shape); + query = q; + } + } + } + if (query == null) return null; + query.Field = field; + return query; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj index 7afd064a924..34036242891 100644 --- a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj +++ b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj @@ -353,7 +353,14 @@ - + + + + + + + + @@ -783,9 +790,16 @@ Always - + + Always + + + + + + Always diff --git a/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs b/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs index 5bde02a83bc..ccab812dc37 100644 --- a/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs +++ b/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs @@ -1,5 +1,7 @@ using FluentAssertions; using NUnit.Framework; +using System.Collections.Generic; +using System.Linq; namespace Nest.Tests.Unit.QueryParsers.Filter { @@ -8,22 +10,204 @@ public class GeoShapeFilterTests : ParseFilterTestsBase { [Test] [TestCase("cacheName", "cacheKey", true)] - public void GeoShape_Deserializes(string cacheName, string cacheKey, bool cache) + public void GeoShapeEnvelope_Deserializes(string cacheName, string cacheKey, bool cache) { - var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, - f=>f.GeoShape, - f=>f.GeoShape(p=>p.Origin, d=>d - .Type("envelope") + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapeEnvelope(p => p.Origin, d => d .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) - ) - ); - geoBaseShapeFilter.Field.Should().Be("origin"); - var geoShapeFilter = geoBaseShapeFilter as IGeoShapeFilter; - geoShapeFilter.Should().NotBeNull(); - geoShapeFilter.Shape.Should().NotBeNull(); - geoShapeFilter.Shape.Type.Should().Be("envelope"); + ) + ); + var filter = geoBaseShapeFilter as IGeoShapeEnvelopeFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("envelope"); + } + + [Test] + [TestCase("cacheName", "cacheKey", true)] + public void GeoShapeCircle_Deserializes(string cacheName, string cacheKey, bool cache) + { + var coordinates = new[] { -45.0, 45.0 }; + + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapeCircle(p => p.Origin, d => d + .Coordinates(coordinates) + .Radius("100m") + ) + ); + + var filter = geoBaseShapeFilter as IGeoShapeCircleFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("circle"); + filter.Shape.Radius.Should().Be("100m"); + filter.Shape.Coordinates.Should().BeEquivalentTo(coordinates); + } + + [Test] + [TestCase("cacheName", "cacheKey", true)] + public void GeoShapeLineString_Deserializes(string cacheName, string cacheKey, bool cache) + { + var coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }; + + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapeLineString(p => p.Origin, d => d + .Coordinates(coordinates) + ) + ); + + var filter = geoBaseShapeFilter as IGeoShapeLineStringFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("linestring"); + filter.Shape.Coordinates.SelectMany(c => c).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c)); + } + + [Test] + [TestCase("cacheName", "cacheKey", true)] + public void GeoShapeMultiLineString_Deserializes(string cacheName, string cacheKey, bool cache) + { + var coordinates = new[] + { + new[] { new[] { 102.0, 2.0 }, new[] { 103.0, 2.0 }, new[] { 103.0, 3.0 }, new[] { 102.0, 3.0 } }, + new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 } }, + new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 } } + }; + + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapeMultiLineString(p => p.Origin, d => d + .Coordinates(coordinates) + ) + ); + + var filter = geoBaseShapeFilter as IGeoShapeMultiLineStringFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("multilinestring"); + filter.Shape.Coordinates.SelectMany(c => c.SelectMany(cc => cc)).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c.SelectMany(cc => cc))); + } + + [Test] + [TestCase("cacheName", "cacheKey", true)] + public void GeoShapePoint_Deserializes(string cacheName, string cacheKey, bool cache) + { + var coordinates = new[] { 1.0, 2.0 }; + + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapePoint(p => p.Origin, d => d + .Coordinates(coordinates) + ) + ); + + var filter = geoBaseShapeFilter as IGeoShapePointFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("point"); + filter.Shape.Coordinates.Should().BeEquivalentTo(coordinates); + } + + [Test] + [TestCase("cacheName", "cacheKey", true)] + public void GeoShapeMultiPoint_Deserializes(string cacheName, string cacheKey, bool cache) + { + var coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }; + + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapeMultiPoint(p => p.Origin, d => d + .Coordinates(coordinates) + ) + ); + + var filter = geoBaseShapeFilter as IGeoShapeMultiPointFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("multipoint"); + filter.Shape.Coordinates.SelectMany(c => c).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c)); + } + + [Test] + [TestCase("cacheName", "cacheKey", true)] + public void GeoShapePolygon_Deserializes(string cacheName, string cacheKey, bool cache) + { + var coordinates = new[] + { + new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 }, new [] { 100.0, 0.0 } }, + new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 }, new [] { 100.2, 0.2 } } + }; + + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapePolygon(p => p.Origin, d => d + .Coordinates(coordinates) + ) + ); + + var filter = geoBaseShapeFilter as IGeoShapePolygonFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("polygon"); + filter.Shape.Coordinates.SelectMany(c => c.SelectMany(cc => cc)).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c.SelectMany(cc => cc))); + } + + [Test] + [TestCase("cacheName", "cacheKey", true)] + public void GeoShapeMultiPolygon_Deserializes(string cacheName, string cacheKey, bool cache) + { + var coordinates = new[] + { + new [] { + new [] { + new [] { 102.0, 2.0 }, new [] { 103.0, 2.0 }, new [] { 103.0, 3.0 }, new [] { 102.0, 3.0 }, new [] { 102.0, 2.0 } + } + }, + new [] { + new [] { + new [] { 100.0, 0.0 }, new [] { 101.0, 0.0 }, new [] { 101.0, 1.0 }, new [] {100.0, 1.0 }, new [] { 100.0, 0.0 } + }, + new [] { + new [] { 100.2, 0.2 }, new [] { 100.8, 0.2 }, new [] { 100.8, 0.8 }, new [] { 100.2, 0.8 }, new [] { 100.2, 0.2 } + } + } + }; + + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShapeMultiPolygon(p => p.Origin, d => d + .Coordinates(coordinates) + ) + ); + + var filter = geoBaseShapeFilter as IGeoShapeMultiPolygonFilter; + filter.Should().NotBeNull(); + filter.Field.Should().Be("origin"); + filter.Should().NotBeNull(); + filter.Shape.Should().NotBeNull(); + filter.Shape.Type.Should().Be("multipolygon"); } - } } \ No newline at end of file diff --git a/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs b/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs index efb3042d8a3..d8af697e4c5 100644 --- a/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs +++ b/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs @@ -1,6 +1,7 @@ using System.Linq; using FluentAssertions; using NUnit.Framework; +using System.Collections.Generic; namespace Nest.Tests.Unit.QueryParsers.Queries { @@ -9,22 +10,201 @@ public class GeoShapeQueryTests : ParseQueryTestsBase { [Test] - public void GeoShape_Deserializes() + public void GeoShapeEnvelope_Deserializes() { var q = this.SerializeThenDeserialize( - f=>f.GeoShape, - f=>f.GeoShape(gq=>gq - .OnField(p=>p.MyGeoShape) - .Coordinates(new [] { new [] {13.0, 53.0}, new [] { 14.0, 52.0} }) - .Type("enveloppe") + f => f.GeoShape, + f => f.GeoShapeEnvelope(gq => gq + .OnField(p => p.MyGeoShape) + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) ) ); - q.Field.Should().Be("myGeoShape"); - q.Shape.Should().NotBeNull(); - q.Shape.Type.Should().Be("enveloppe"); - q.Shape.Coordinates.SelectMany(c=>c).Should() + var query = q as IGeoShapeEnvelopeQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Type.Should().Be("envelope"); + query.Shape.Coordinates.SelectMany(c=>c).Should() .BeEquivalentTo(new [] {13.0, 53.0, 14.0, 52.0 }); } + + [Test] + public void GeoShapeCircle_Deserializes() + { + var coordinates = new[] { -45.0, 45.0 }; + + var q = this.SerializeThenDeserialize( + f => f.GeoShape, + f => f.GeoShapeCircle(gq => gq + .OnField(p => p.MyGeoShape) + .Radius("100m") + .Coordinates(coordinates) + ) + ); + + var query = q as IGeoShapeCircleQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Should().NotBeNull(); + query.Shape.Type.Should().Be("circle"); + query.Shape.Radius.Should().Be("100m"); + query.Shape.Coordinates.Should().BeEquivalentTo(coordinates); + } + + [Test] + public void GeoShapeLineString_Deserializes() + { + var coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }; + + var q = this.SerializeThenDeserialize( + f => f.GeoShape, + f => f.GeoShapeLineString(gq => gq + .OnField(p => p.MyGeoShape) + .Coordinates(coordinates) + ) + ); + + var query = q as IGeoShapeLineStringQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Should().NotBeNull(); + query.Shape.Type.Should().Be("linestring"); + query.Shape.Coordinates.SelectMany(c => c).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c)); + } + + [Test] + public void GeoShapeMultiLineString_Deserializes() + { + var coordinates = new[] + { + new[] { new[] { 102.0, 2.0 }, new[] { 103.0, 2.0 }, new[] { 103.0, 3.0 }, new[] { 102.0, 3.0 } }, + new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 } }, + new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 } } + }; + + var q = this.SerializeThenDeserialize( + f => f.GeoShape, + f => f.GeoShapeMultiLineString(gq => gq + .OnField(p => p.MyGeoShape) + .Coordinates(coordinates) + ) + ); + + var query = q as IGeoShapeMultiLineStringQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Should().NotBeNull(); + query.Shape.Type.Should().Be("multilinestring"); + query.Shape.Coordinates.SelectMany(c => c.SelectMany(cc => cc)).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c.SelectMany(cc => cc))); + } + + [Test] + public void GeoShapePoint_Deserializes() + { + var coordinates = new[] { 1.0, 2.0 }; + + var q = this.SerializeThenDeserialize( + f => f.GeoShape, + f => f.GeoShapePoint(gq => gq + .OnField(p => p.MyGeoShape) + .Coordinates(coordinates) + ) + ); + + var query = q as IGeoShapePointQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Should().NotBeNull(); + query.Shape.Type.Should().Be("point"); + query.Shape.Coordinates.Should().BeEquivalentTo(coordinates); + } + + [Test] + public void GeoShapeMultiPoint_Deserializes() + { + var coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }; + + var q = this.SerializeThenDeserialize( + f => f.GeoShape, + f => f.GeoShapeMultiPoint(gq => gq + .OnField(p => p.MyGeoShape) + .Coordinates(coordinates) + ) + ); + + var query = q as IGeoShapeMultiPointQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Should().NotBeNull(); + query.Shape.Type.Should().Be("multipoint"); + query.Shape.Coordinates.SelectMany(c => c).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c)); + } + + [Test] + public void GeoShapePolygon_Deserializes() + { + var coordinates = new[] + { + new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 }, new [] { 100.0, 0.0 } }, + new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 }, new [] { 100.2, 0.2 } } + }; + + var q = this.SerializeThenDeserialize( + f => f.GeoShape, + f => f.GeoShapePolygon(gq => gq + .OnField(p => p.MyGeoShape) + .Coordinates(coordinates) + ) + ); + + var query = q as IGeoShapePolygonQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Should().NotBeNull(); + query.Shape.Type.Should().Be("polygon"); + query.Shape.Coordinates.SelectMany(c => c.SelectMany(cc => cc)).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c.SelectMany(cc => cc))); + } + + [Test] + public void GeoShapeMultiPolygon_Deserializes() + { + var coordinates = new[] + { + new [] { + new [] { + new [] { 102.0, 2.0 }, new [] { 103.0, 2.0 }, new [] { 103.0, 3.0 }, new [] { 102.0, 3.0 }, new [] { 102.0, 2.0 } + } + }, + new [] { + new [] { + new [] { 100.0, 0.0 }, new [] { 101.0, 0.0 }, new [] { 101.0, 1.0 }, new [] {100.0, 1.0 }, new [] { 100.0, 0.0 } + }, + new [] { + new [] { 100.2, 0.2 }, new [] { 100.8, 0.2 }, new [] { 100.8, 0.8 }, new [] { 100.2, 0.8 }, new [] { 100.2, 0.2 } + } + } + }; + + var q = this.SerializeThenDeserialize( + f => f.GeoShape, + f => f.GeoShapeMultiPolygon(gq => gq + .OnField(p => p.MyGeoShape) + .Coordinates(coordinates) + ) + ); + + var query = q as IGeoShapeMultiPolygonQuery; + query.Should().NotBeNull(); + query.Field.Should().Be("myGeoShape"); + query.Shape.Should().NotBeNull(); + query.Shape.Type.Should().Be("multipolygon"); + query.Shape.Coordinates.SelectMany(c => c.SelectMany(cc => cc.SelectMany(ccc => ccc))).Should() + .BeEquivalentTo(coordinates.SelectMany(c => c.SelectMany(cc => cc.SelectMany(ccc => ccc)))); + } + } } \ No newline at end of file diff --git a/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoIndexedShapeFilterJson.cs b/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoIndexedShapeFilterJson.cs index 22557320898..cdb1f6b519c 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoIndexedShapeFilterJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoIndexedShapeFilterJson.cs @@ -30,7 +30,7 @@ public void GeoShapeFilter() id: ""1"", type: ""elasticsearchprojects"", index: ""nest_test_data"", - shape_field_name: ""myGeoShape"" + path: ""myGeoShape"" } }, _cache: true, diff --git a/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs b/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs index 4497915e430..bf9b484fe2a 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using Nest.Tests.MockData.Domain; +using System.Collections.Generic; namespace Nest.Tests.Unit.Search.Filter.Singles { @@ -7,20 +8,19 @@ namespace Nest.Tests.Unit.Search.Filter.Singles public class GeoShapeFilterJson { [Test] - public void GeoShapeFilter() + public void GeoShapeEnvelopeFilter() { //[13.0, 53.0], [14.0, 52.0]] var s = new SearchDescriptor() .From(0) .Size(10) .Filter(filter => filter - .Cache(true) + .Cache(true) .Name("my_geo_filter") - .GeoShape(f=>f.Origin, d=>d - .Type("envelope") + .GeoShapeEnvelope(f => f.Origin, d => d .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) - ) - ); + ) + ); var json = TestElasticClient.Serialize(s); var expected = @"{ from: 0, size: 10, @@ -28,8 +28,8 @@ public void GeoShapeFilter() geo_shape: { origin: { shape: { - type: ""envelope"", - coordinates: [[13.0, 53.0], [14.0, 52.0]] + coordinates: [[13.0, 53.0], [14.0, 52.0]], + type: ""envelope"" } }, _cache: true, @@ -40,5 +40,265 @@ public void GeoShapeFilter() Assert.True(json.JsonEquals(expected), json); } + [Test] + public void GeoShapeCircleFilter() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Filter(f => f + .Cache(true) + .Name("my_geo_filter") + .GeoShapeCircle(p => p.Origin, d => d + .Coordinates(new[] { -45.0, 45.0 }) + .Radius("100m") + ) + ); + + var json = TestElasticClient.Serialize(s); + var expected = @"{ from: 0, size: 10, + filter : { + geo_shape: { + origin: { + shape: { + coordinates: [ -45.0, 45.0 ], + radius: ""100m"", + type: ""circle"" + } + }, + _cache: true, + _name: ""my_geo_filter"" + } + } + }"; + Assert.IsTrue(json.JsonEquals(expected), json); + } + + [Test] + public void GeoShapeLineStringFilter() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Filter(f => f + .Cache(true) + .Name("my_geo_filter") + .GeoShapeLineString(p => p.Origin, d => d + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) + ) + ); + + var json = TestElasticClient.Serialize(s); + var expected = @"{ from: 0, size: 10, + filter : { + geo_shape: { + origin: { + shape: { + coordinates: [ + [ 13.0, 53.0 ], [ 14.0, 52.0 ] + ], + type: ""linestring"" + } + }, + _cache: true, + _name: ""my_geo_filter"" + } + } + }"; + Assert.IsTrue(json.JsonEquals(expected), json); + } + + [Test] + public void GeoShapeMultiLineStringFilter() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Filter(f => f + .Cache(true) + .Name("my_geo_filter") + .GeoShapeMultiLineString(p => p.Origin, d => d + .Coordinates(new[] { + new[] { new[] { 102.0, 2.0 }, new[] { 103.0, 2.0 }, new[] { 103.0, 3.0 }, new[] { 102.0, 3.0 } }, + new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 } }, + new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 } } + }) + ) + ); + + var json = TestElasticClient.Serialize(s); + var expected = @"{ from: 0, size: 10, + filter : { + geo_shape: { + origin: { + shape: { + coordinates: [ + [ [ 102.0, 2.0 ], [ 103.0, 2.0 ], [ 103.0, 3.0 ], [ 102.0, 3.0 ] ], + [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ] ], + [ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ] ] + ], + type: ""multilinestring"" + } + }, + _cache: true, + _name: ""my_geo_filter"" + } + } + }"; + Assert.IsTrue(json.JsonEquals(expected), json); + } + + [Test] + public void GeoShapePointFilter() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Filter(f => f + .Cache(true) + .Name("my_geo_filter") + .GeoShapePoint(p => p.Origin, d => d + .Coordinates(new [] { 1.0, 2.0 }) + ) + ); + + var json = TestElasticClient.Serialize(s); + var expected = @"{ from: 0, size: 10, + filter : { + geo_shape: { + origin: { + shape: { + coordinates:[ 1.0, 2.0 ], + type: ""point"" + } + }, + _cache: true, + _name: ""my_geo_filter"" + } + } + }"; + Assert.IsTrue(json.JsonEquals(expected), json); + } + + public void GeoShapeMultiPointFilter() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Filter(f => f + .Cache(true) + .Name("my_geo_filter") + .GeoShapeMultiPoint(p => p.Origin, d => d + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) + ) + ); + + var json = TestElasticClient.Serialize(s); + var expected = @"{ from: 0, size: 10, + filter : { + geo_shape: { + origin: { + shape: { + coordinates:[ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ], + type: ""multipoint"" + } + }, + _cache: true, + _name: ""my_geo_filter"" + } + } + }"; + Assert.IsTrue(json.JsonEquals(expected), json); + } + + [Test] + public void GeoShapePolygonFilter() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Filter(f => f + .Cache(true) + .Name("my_geo_filter") + .GeoShapePolygon(p => p.Origin, d => d + .Coordinates(new[] { + new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 }, new [] { 100.0, 0.0 } }, + new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 }, new [] { 100.2, 0.2 } } + }) + ) + ); + + var json = TestElasticClient.Serialize(s); + var expected = @"{ from: 0, size: 10, + filter : { + geo_shape: { + origin: { + shape: { + coordinates: [ + [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ], + [ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ], [ 100.2, 0.2 ] ] + ], + type: ""polygon"" + } + }, + _cache: true, + _name: ""my_geo_filter"" + } + } + }"; + Assert.IsTrue(json.JsonEquals(expected), json); + } + + [Test] + public void GeoShapeMultiPolygonFilter() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Filter(f => f + .Cache(true) + .Name("my_geo_filter") + .GeoShapeMultiPolygon(p => p.Origin, d => d + .Coordinates(new[] { + new [] { + new [] { + new [] { 102.0, 2.0 }, new [] { 103.0, 2.0 }, new [] { 103.0, 3.0 }, new [] { 102.0, 3.0 }, new [] { 102.0, 2.0 } + } + }, + new [] { + new [] { + new [] { 100.0, 0.0 }, new [] { 101.0, 0.0 }, new [] { 101.0, 1.0 }, new [] {100.0, 1.0 }, new [] { 100.0, 0.0 } + }, + new [] { + new [] { 100.2, 0.2 }, new [] { 100.8, 0.2 }, new [] { 100.8, 0.8 }, new [] { 100.2, 0.8 }, new [] { 100.2, 0.2 } + } + } + }) + ) + ); + + var json = TestElasticClient.Serialize(s); + var expected = @"{ from: 0, size: 10, + filter : { + geo_shape: { + origin: { + shape: { + coordinates:[ + [ [ [ 102.0, 2.0 ], [ 103.0, 2.0 ], [ 103.0, 3.0 ], [ 102.0, 3.0 ], [ 102.0, 2.0 ] ] ], + [ + [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ], + [ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ], [ 100.2, 0.2 ] ] + ] + ], + type: ""multipolygon"" + } + }, + _cache: true, + _name: ""my_geo_filter"" + } + } + }"; + Assert.IsTrue(json.JsonEquals(expected), json); + } } } diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircle.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircle.json new file mode 100644 index 00000000000..abcc06cd16a --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircle.json @@ -0,0 +1,15 @@ +{ + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "coordinates": [ -45.0, 45.0 ], + "radius": "100m", + "type": "circle" + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircleJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircleJson.cs new file mode 100644 index 00000000000..5e3c1f517dd --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircleJson.cs @@ -0,0 +1,32 @@ +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape +{ + [TestFixture] + public class GeoShapeCircleJson : BaseJsonTests + { + [Test] + public void GeoShapeCircle() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShapeCircle(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates(new[] { -45.0, 45.0 }) + .Radius("100m") + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeFull.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelope.json similarity index 82% rename from src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeFull.json rename to src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelope.json index b352910761c..c76fd375a6e 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeFull.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelope.json @@ -5,10 +5,10 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "enveloppe", "coordinates": [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] - ] + ], + "type": "envelope" } } } diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeQueryJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelopeJson.cs similarity index 54% rename from src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeQueryJson.cs rename to src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelopeJson.cs index dc6808e6465..11e8be6b3eb 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeQueryJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelopeJson.cs @@ -1,26 +1,26 @@ using System.Reflection; using Nest.Tests.MockData.Domain; using NUnit.Framework; +using System.Collections.Generic; namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape { [TestFixture] - public class GeoShapeQueryJson : BaseJsonTests + public class GeoShapeEnvelopeJson : BaseJsonTests { [Test] - public void GeoShapeFull() + public void GeoShapeEnvelope() { var s = new SearchDescriptor() .From(0) .Size(10) - .Query(q=>q - .GeoShape(qs=>qs - .OnField(p=>p.MyGeoShape) - .Coordinates(new [] { new [] {13.0, 53.0}, new [] { 14.0, 52.0} }) - .Type("enveloppe") + .Query(q => q + .GeoShapeEnvelope(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) ) ); - + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); } } diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineString.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineString.json new file mode 100644 index 00000000000..b8c7a9f6cd9 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineString.json @@ -0,0 +1,16 @@ + { + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "coordinates": [ + [ 13.0, 53.0 ], [ 14.0, 52.0 ] + ], + "type": "linestring" + } + } + } + } +} \ No newline at end of file diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineStringJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineStringJson.cs new file mode 100644 index 00000000000..e3b30722955 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineStringJson.cs @@ -0,0 +1,31 @@ +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape +{ + [TestFixture] + public class GeoShapeLineStringJson : BaseJsonTests + { + [Test] + public void GeoShapeLineString() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShapeLineString(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineString.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineString.json new file mode 100644 index 00000000000..d3471e61e4a --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineString.json @@ -0,0 +1,18 @@ +{ + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "coordinates": [ + [ [ 102.0, 2.0 ], [ 103.0, 2.0 ], [ 103.0, 3.0 ], [ 102.0, 3.0 ] ], + [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ] ], + [ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ] ] + ], + "type": "multilinestring" + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineStringJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineStringJson.cs new file mode 100644 index 00000000000..05c1aa6c80a --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineStringJson.cs @@ -0,0 +1,35 @@ +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape +{ + [TestFixture] + public class GeoShapeMultiLineStringJson : BaseJsonTests + { + [Test] + public void GeoShapeMultiLineString() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShapeMultiLineString(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates(new[] { + new[] { new[] { 102.0, 2.0 }, new[] { 103.0, 2.0 }, new[] { 103.0, 3.0 }, new[] { 102.0, 3.0 } }, + new[] { new[] { 100.0, 0.0}, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0}, new[] { 100.0, 1.0 } }, + new[] { new[] { 100.2, 0.2}, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8}, new[] { 100.2, 0.8 } } + }) + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPoint.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPoint.json new file mode 100644 index 00000000000..da9c8dbe7bf --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPoint.json @@ -0,0 +1,17 @@ +{ + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "coordinates": [ + [ 13.0, 53.0 ], + [ 14.0, 52.0 ] + ], + "type": "multipoint" + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPointJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPointJson.cs new file mode 100644 index 00000000000..8f62b6c11a3 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPointJson.cs @@ -0,0 +1,31 @@ +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape +{ + [TestFixture] + public class GeoShapeMultiPointJson : BaseJsonTests + { + [Test] + public void GeoShapeMultiPoint() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShapeMultiPoint(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygon.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygon.json new file mode 100644 index 00000000000..25a6a399224 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygon.json @@ -0,0 +1,20 @@ +{ + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "coordinates": [ + [ [ [ 102.0, 2.0 ], [ 103.0, 2.0 ], [ 103.0, 3.0 ], [ 102.0, 3.0 ], [ 102.0, 2.0 ] ] ], + [ + [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ], + [ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ], [ 100.2, 0.2 ] ] + ] + ], + "type": "multipolygon" + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygonJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygonJson.cs new file mode 100644 index 00000000000..e841290a060 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygonJson.cs @@ -0,0 +1,47 @@ +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape +{ + [TestFixture] + public class GeoShapeMultiPolygonJson : BaseJsonTests + { + [Test] + public void GeoShapeMultiPolygon() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShapeMultiPolygon(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates( + new[] { + new [] { + new [] { + new [] { 102.0, 2.0 }, new [] { 103.0, 2.0 }, new [] { 103.0, 3.0 }, new [] { 102.0, 3.0 }, new [] { 102.0, 2.0 } + } + }, + new [] { + new [] { + new [] { 100.0, 0.0 }, new [] { 101.0, 0.0 }, new [] { 101.0, 1.0 }, new [] {100.0, 1.0 }, new [] { 100.0, 0.0 } + }, + new [] { + new [] { 100.2, 0.2 }, new [] { 100.8, 0.2 }, new [] { 100.8, 0.8 }, new [] { 100.2, 0.8 }, new [] { 100.2, 0.2 } + } + } + } + ) + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePoint.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePoint.json new file mode 100644 index 00000000000..e36c1aa09d2 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePoint.json @@ -0,0 +1,14 @@ +{ + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "coordinates": [ -45.0, 45.0 ], + "type": "point" + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePointJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePointJson.cs new file mode 100644 index 00000000000..4f715be5dd8 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePointJson.cs @@ -0,0 +1,31 @@ +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape +{ + [TestFixture] + public class GeoShapePointJson : BaseJsonTests + { + [Test] + public void GeoShapePoint() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShapePoint(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates(new[] { -45.0, 45.0 }) + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygon.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygon.json new file mode 100644 index 00000000000..8735768489c --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygon.json @@ -0,0 +1,17 @@ +{ + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "coordinates": [ + [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ], + [ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ], [ 100.2, 0.2 ] ] + ], + "type": "polygon" + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygonJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygonJson.cs new file mode 100644 index 00000000000..61b45c60a73 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygonJson.cs @@ -0,0 +1,39 @@ +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Search.Query.Singles.GeoShape +{ + [TestFixture] + public class GeoShapePolygonJson : BaseJsonTests + { + [Test] + public void GeoShapePolygon() + { + var polygon = new PolygonGeoShape + { + Coordinates = new[] { + new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 }, new [] { 100.0, 0.0 } }, + new[] { new[] { 100.2, 0.2}, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8}, new[] { 100.2, 0.8 }, new [] { 100.2, 0.2} } + } + }; + + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShapePolygon(qs => qs + .OnField(p => p.MyGeoShape) + .Coordinates(polygon.Coordinates) + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +}