From 982fc922a52954e28d61b0ef0c40d4c0370d3939 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 14 Jul 2014 13:20:46 -0400 Subject: [PATCH 01/14] Better GeoJSON object support for geo shape queries/filters --- .../DSL/Filter/GeoShapeFilterDescriptor.cs | 25 +++------- src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs | 39 ++++++--------- .../DSL/{GeoShapeVector.cs => GeoShape.cs} | 9 ++-- src/Nest/Domain/Geometry/Circle.cs | 28 +++++++++++ src/Nest/Domain/Geometry/Envelope.cs | 19 +++++++ src/Nest/Domain/Geometry/GeometryObject.cs | 31 ++++++++++++ src/Nest/Domain/Geometry/IGeometryObject.cs | 14 ++++++ src/Nest/Domain/Geometry/LineString.cs | 19 +++++++ src/Nest/Domain/Geometry/MultiLineString.cs | 19 +++++++ src/Nest/Domain/Geometry/MultiPoint.cs | 19 +++++++ src/Nest/Domain/Geometry/MultiPolygon.cs | 19 +++++++ src/Nest/Domain/Geometry/Point.cs | 19 +++++++ src/Nest/Domain/Geometry/Polygon.cs | 19 +++++++ src/Nest/Nest.csproj | 12 ++++- .../Filters/GeoShapeFilterJsonReader.cs | 2 +- .../Nest.Tests.Unit/Nest.Tests.Unit.csproj | 18 ++++++- .../Filter/GeoShapeFilterTests.cs | 11 ++-- .../Queries/GeoShapeQueryTests.cs | 16 +++--- .../Filter/Singles/GeoShapeFilterJson.cs | 16 +++--- .../Singles/GeoShape/GeoShapeCircle.json | 15 ++++++ .../Singles/GeoShape/GeoShapeCircleJson.cs | 31 ++++++++++++ ...eoShapeFull.json => GeoShapeEnvelope.json} | 2 +- ...peQueryJson.cs => GeoShapeEnvelopeJson.cs} | 16 +++--- .../Singles/GeoShape/GeoShapeLineString.json | 16 ++++++ .../GeoShape/GeoShapeLineStringJson.cs | 31 ++++++++++++ .../GeoShape/GeoShapeMultiLineString.json | 18 +++++++ .../GeoShape/GeoShapeMultiLineStringJson.cs | 38 ++++++++++++++ .../Singles/GeoShape/GeoShapeMultiPoint.json | 16 ++++++ .../GeoShape/GeoShapeMultiPointJson.cs | 31 ++++++++++++ .../GeoShape/GeoShapeMultiPolygon.json | 20 ++++++++ .../GeoShape/GeoShapeMultiPolygonJson.cs | 50 +++++++++++++++++++ .../Query/Singles/GeoShape/GeoShapePoint.json | 14 ++++++ .../Singles/GeoShape/GeoShapePointJson.cs | 31 ++++++++++++ .../Singles/GeoShape/GeoShapePolygon.json | 17 +++++++ .../Singles/GeoShape/GeoShapePolygonJson.cs | 39 +++++++++++++++ 35 files changed, 662 insertions(+), 77 deletions(-) rename src/Nest/Domain/DSL/{GeoShapeVector.cs => GeoShape.cs} (68%) create mode 100644 src/Nest/Domain/Geometry/Circle.cs create mode 100644 src/Nest/Domain/Geometry/Envelope.cs create mode 100644 src/Nest/Domain/Geometry/GeometryObject.cs create mode 100644 src/Nest/Domain/Geometry/IGeometryObject.cs create mode 100644 src/Nest/Domain/Geometry/LineString.cs create mode 100644 src/Nest/Domain/Geometry/MultiLineString.cs create mode 100644 src/Nest/Domain/Geometry/MultiPoint.cs create mode 100644 src/Nest/Domain/Geometry/MultiPolygon.cs create mode 100644 src/Nest/Domain/Geometry/Point.cs create mode 100644 src/Nest/Domain/Geometry/Polygon.cs create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircle.json create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircleJson.cs rename src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/{GeoShapeFull.json => GeoShapeEnvelope.json} (87%) rename src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/{GeoShapeQueryJson.cs => GeoShapeEnvelopeJson.cs} (53%) create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineString.json create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineStringJson.cs create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineString.json create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineStringJson.cs create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPoint.json create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPointJson.cs create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygon.json create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygonJson.cs create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePoint.json create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePointJson.cs create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygon.json create mode 100644 src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygonJson.cs diff --git a/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs index c99e0062956..9cd14607ecc 100644 --- a/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs +++ b/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs @@ -18,7 +18,7 @@ public interface IGeoShapeBaseFilter : IFieldNameFilter public interface IGeoShapeFilter : IGeoShapeBaseFilter { [JsonProperty("shape")] - GeoShapeVector Shape { get; set; } + GeoShape Shape { get; set; } } public class GeoShapeFilter : PlainFilter, IGeoShapeFilter @@ -30,38 +30,29 @@ protected internal override void WrapInContainer(IFilterContainer container) public PropertyPathMarker Field { get; set; } - public GeoShapeVector Shape { get; set; } + public GeoShape Shape { get; set; } } public class GeoShapeFilterDescriptor : FilterBase, IGeoShapeFilter { + IGeoShapeFilter Self { get { return this; } } + bool IFilter.IsConditionless { get { - return ((IGeoShapeFilter)this).Shape == null || !((IGeoShapeFilter)this).Shape.Coordinates.HasAny(); + return this.Self.Shape == null; } } 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; - } + GeoShape IGeoShapeFilter.Shape { get; set; } - public GeoShapeFilterDescriptor Coordinates(IEnumerable> coordinates) + public GeoShapeFilterDescriptor Shape(IGeometryObject shape) { - if (((IGeoShapeFilter)this).Shape == null) - ((IGeoShapeFilter)this).Shape = new GeoShapeVector(); - ((IGeoShapeFilter)this).Shape.Coordinates = coordinates; + this.Self.Shape = shape.ToGeoShape(); return this; } - } } diff --git a/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs index 27a17267af1..9e06311534f 100644 --- a/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs +++ b/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs @@ -16,7 +16,7 @@ public interface IGeoShapeQuery : IFieldNameQuery PropertyPathMarker Field { get; set; } [JsonProperty("shape")] - GeoShapeVector Shape { get; set; } + GeoShape Shape { get; set; } } public class GeoShapeQuery : PlainQuery, IGeoShapeQuery @@ -39,60 +39,51 @@ void IFieldNameQuery.SetFieldName(string fieldName) } public PropertyPathMarker Field { get; set; } - public GeoShapeVector Shape { get; set; } + + public GeoShape Shape { get; set; } } public class GeoShapeQueryDescriptor : IGeoShapeQuery where T : class { + IGeoShapeQuery Self { get { return this; } } + PropertyPathMarker IGeoShapeQuery.Field { get; set; } - GeoShapeVector IGeoShapeQuery.Shape { get; set; } - + GeoShape IGeoShapeQuery.Shape { get; set; } + bool IQuery.IsConditionless { get { - return ((IGeoShapeQuery)this).Field.IsConditionless() || (((IGeoShapeQuery)this).Shape == null || !((IGeoShapeQuery)this).Shape.Coordinates.HasAny()); + return this.Self.Field.IsConditionless() || this.Self.Shape == null; } } void IFieldNameQuery.SetFieldName(string fieldName) { - ((IGeoShapeQuery)this).Field = fieldName; + this.Self.Field = fieldName; } PropertyPathMarker IFieldNameQuery.GetFieldName() { - return ((IGeoShapeQuery)this).Field; + return this.Self.Field; } public GeoShapeQueryDescriptor OnField(string field) { - ((IGeoShapeQuery)this).Field = field; + this.Self.Field = field; return this; } public GeoShapeQueryDescriptor OnField(Expression> objectPath) { - ((IGeoShapeQuery)this).Field = objectPath; + this.Self.Field = objectPath; return this; } - - public GeoShapeQueryDescriptor Type(string type) + public GeoShapeQueryDescriptor Shape(IGeometryObject shape) { - if (((IGeoShapeQuery)this).Shape == null) - ((IGeoShapeQuery)this).Shape = new GeoShapeVector(); - ((IGeoShapeQuery)this).Shape.Type = type; + shape.ThrowIfNull("shape"); + this.Self.Shape = shape.ToGeoShape(); return this; } - - public GeoShapeQueryDescriptor Coordinates(IEnumerable> coordinates) - { - if (((IGeoShapeQuery)this).Shape == null) - ((IGeoShapeQuery)this).Shape = new GeoShapeVector(); - ((IGeoShapeQuery)this).Shape.Coordinates = coordinates; - return this; - } - } - } diff --git a/src/Nest/Domain/DSL/GeoShapeVector.cs b/src/Nest/Domain/DSL/GeoShape.cs similarity index 68% rename from src/Nest/Domain/DSL/GeoShapeVector.cs rename to src/Nest/Domain/DSL/GeoShape.cs index 30283890c9f..86333732633 100644 --- a/src/Nest/Domain/DSL/GeoShapeVector.cs +++ b/src/Nest/Domain/DSL/GeoShape.cs @@ -7,15 +7,18 @@ namespace Nest { /// - /// An object to describe a geoshape vetor + /// An object to describe a geoshape /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html /// - public class GeoShapeVector + public class GeoShape { [JsonProperty("type")] public string Type { get; set; } [JsonProperty("coordinates")] - public IEnumerable> Coordinates { get; set; } + public object Coordinates { get; set; } + + [JsonProperty("radius")] + public string Radius { get; set; } } } diff --git a/src/Nest/Domain/Geometry/Circle.cs b/src/Nest/Domain/Geometry/Circle.cs new file mode 100644 index 00000000000..d5be0c882f0 --- /dev/null +++ b/src/Nest/Domain/Geometry/Circle.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class Circle + : GeometryObject> + { + public Circle() : this(null) { } + + public Circle(IEnumerable coordinates) + : base("circle") + { + this.Coordinates = coordinates ?? new List(); + } + + public string Radius { get; set; } + + public override GeoShape ToGeoShape() + { + var shape = base.ToGeoShape(); + shape.Radius = this.Radius; + return shape; + } + } +} diff --git a/src/Nest/Domain/Geometry/Envelope.cs b/src/Nest/Domain/Geometry/Envelope.cs new file mode 100644 index 00000000000..0145ec88575 --- /dev/null +++ b/src/Nest/Domain/Geometry/Envelope.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class Envelope + : GeometryObject>> + { + public Envelope() : this(null) { } + + public Envelope(IEnumerable> coordinates) + : base("envelope") + { + this.Coordinates = coordinates ?? new List>(); + } + } +} diff --git a/src/Nest/Domain/Geometry/GeometryObject.cs b/src/Nest/Domain/Geometry/GeometryObject.cs new file mode 100644 index 00000000000..c329e2defa0 --- /dev/null +++ b/src/Nest/Domain/Geometry/GeometryObject.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public abstract class GeometryObject + : IGeometryObject + { + public GeometryObject(string type) + { + this.Type = type; + } + + public string Type { get; protected set; } + + public TCoordinates Coordinates { get; set; } + + public virtual GeoShape ToGeoShape() + { + var shape = new GeoShape + { + Type = this.Type, + Coordinates = this.Coordinates + }; + + return shape; + } + } +} diff --git a/src/Nest/Domain/Geometry/IGeometryObject.cs b/src/Nest/Domain/Geometry/IGeometryObject.cs new file mode 100644 index 00000000000..d0700108663 --- /dev/null +++ b/src/Nest/Domain/Geometry/IGeometryObject.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IGeometryObject + { + string Type { get; } + TCoordinates Coordinates { get; set; } + GeoShape ToGeoShape(); + } +} diff --git a/src/Nest/Domain/Geometry/LineString.cs b/src/Nest/Domain/Geometry/LineString.cs new file mode 100644 index 00000000000..e6bd8bd3459 --- /dev/null +++ b/src/Nest/Domain/Geometry/LineString.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class LineString + : GeometryObject>> + { + public LineString() : this(null) { } + + public LineString(IEnumerable> coordinates) + : base("linestring") + { + this.Coordinates = coordinates ?? new List>(); + } + } +} diff --git a/src/Nest/Domain/Geometry/MultiLineString.cs b/src/Nest/Domain/Geometry/MultiLineString.cs new file mode 100644 index 00000000000..5ca17961275 --- /dev/null +++ b/src/Nest/Domain/Geometry/MultiLineString.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class MultiLineString + : GeometryObject>>> + { + public MultiLineString() : this(null) { } + + public MultiLineString(IEnumerable>> coordinates) + : base("multilinestring") + { + this.Coordinates = coordinates ?? new List>>(); + } + } +} diff --git a/src/Nest/Domain/Geometry/MultiPoint.cs b/src/Nest/Domain/Geometry/MultiPoint.cs new file mode 100644 index 00000000000..1ad8f3ac44c --- /dev/null +++ b/src/Nest/Domain/Geometry/MultiPoint.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class MultiPoint : + GeometryObject>> + { + public MultiPoint() : this(null) { } + + public MultiPoint(IEnumerable> coordinates) + : base("multipoint") + { + this.Coordinates = coordinates ?? new List>(); + } + } +} diff --git a/src/Nest/Domain/Geometry/MultiPolygon.cs b/src/Nest/Domain/Geometry/MultiPolygon.cs new file mode 100644 index 00000000000..96c23e60c93 --- /dev/null +++ b/src/Nest/Domain/Geometry/MultiPolygon.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class MultiPolygon + : GeometryObject>>>> + { + public MultiPolygon() : this(null) { } + + public MultiPolygon(IEnumerable>>> coordinates) + : base("multipolygon") + { + this.Coordinates = coordinates ?? new List>>>(); + } + } +} diff --git a/src/Nest/Domain/Geometry/Point.cs b/src/Nest/Domain/Geometry/Point.cs new file mode 100644 index 00000000000..d3b426a51b8 --- /dev/null +++ b/src/Nest/Domain/Geometry/Point.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class Point + : GeometryObject> + { + public Point() : this(null) { } + + public Point(IEnumerable coordinates) + : base("point") + { + this.Coordinates = coordinates ?? new List(); + } + } +} diff --git a/src/Nest/Domain/Geometry/Polygon.cs b/src/Nest/Domain/Geometry/Polygon.cs new file mode 100644 index 00000000000..d942ccafcc7 --- /dev/null +++ b/src/Nest/Domain/Geometry/Polygon.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class Polygon : + GeometryObject< IEnumerable>>> + { + public Polygon() : this(null) { } + + public Polygon(IEnumerable>> coordinates) + : base("polygon") + { + this.Coordinates = coordinates ?? new List>>(); + } + } +} diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index bf6f71deddb..caa81f50236 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -136,6 +136,17 @@ + + + + + + + + + + + @@ -359,7 +370,6 @@ - diff --git a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs index ebc5f2e6d8e..2618787d4de 100644 --- a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs +++ b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs @@ -50,7 +50,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist if (shape != null) { IGeoShapeFilter f = new GeoShapeFilterDescriptor(); - f.Shape = new GeoShapeVector(); + f.Shape = new GeoShape(); var coordinates = shape["coordinates"]; if (coordinates != null) f.Shape.Coordinates = coordinates.Values(); diff --git a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj index 391137792cc..47f6740fa50 100644 --- a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj +++ b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj @@ -352,7 +352,14 @@ - + + + + + + + + @@ -782,9 +789,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..2654ada6a7f 100644 --- a/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs +++ b/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs @@ -1,5 +1,6 @@ using FluentAssertions; using NUnit.Framework; +using System.Collections.Generic; namespace Nest.Tests.Unit.QueryParsers.Filter { @@ -10,11 +11,10 @@ public class GeoShapeFilterTests : ParseFilterTestsBase [TestCase("cacheName", "cacheKey", true)] public void GeoShape_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") - .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) + var geoBaseShapeFilter = this.SerializeThenDeserialize(cacheName, cacheKey, cache, + f => f.GeoShape, + f => f.GeoShape(p => p.Origin, d => d + .Shape(new Envelope { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) ) ); geoBaseShapeFilter.Field.Should().Be("origin"); @@ -22,7 +22,6 @@ public void GeoShape_Deserializes(string cacheName, string cacheKey, bool cache) geoShapeFilter.Should().NotBeNull(); geoShapeFilter.Shape.Should().NotBeNull(); geoShapeFilter.Shape.Type.Should().Be("envelope"); - } } diff --git a/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs b/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs index efb3042d8a3..c44157cfd77 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 { @@ -12,19 +13,18 @@ public class GeoShapeQueryTests : ParseQueryTestsBase public void GeoShape_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.GeoShape(gq => gq + .OnField(p => p.MyGeoShape) + .Shape(new Envelope { 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() - .BeEquivalentTo(new [] {13.0, 53.0, 14.0, 52.0 }); + q.Shape.Type.Should().Be("envelope"); + //((Newtonsoft.Json.Linq.JArray)q.ShapeVector.Coordinates).SelectMany(c=>c).Should() + // .BeEquivalentTo(new [] {13.0, 53.0, 14.0, 52.0 }); } } } \ No newline at end of file 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..c2706047828 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 { @@ -14,13 +15,12 @@ public void GeoShapeFilter() .From(0) .Size(10) .Filter(filter => filter - .Cache(true) + .Cache(true) .Name("my_geo_filter") - .GeoShape(f=>f.Origin, d=>d - .Type("envelope") - .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) - ) - ); + .GeoShape(f => f.Origin, d => d + .Shape(new Envelope { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) + ) + ); var json = TestElasticClient.Serialize(s); var expected = @"{ from: 0, size: 10, @@ -40,5 +40,9 @@ public void GeoShapeFilter() Assert.True(json.JsonEquals(expected), json); } + public void GeoShapeCircleFilter() + { + + } } } 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..1639e996397 --- /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": { + "type": "circle", + "coordinates": [ -45.0, 45.0 ], + "radius": "100m" + } + } + } + } +} 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..060856b7303 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircleJson.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 GeoShapeCircleJson : BaseJsonTests + { + [Test] + public void GeoShapeCircle() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .Query(q => q + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(new Circle { 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 87% 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..57c5437f1d3 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,7 +5,7 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "enveloppe", + "type": "envelope", "coordinates": [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ] 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 53% 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..5088e69d903 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 + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(new Envelope { 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..2f2e3b87bea --- /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": { + "type": "linestring", + "coordinates": [ + [ 13.0, 53.0 ], [ 14.0, 52.0 ] + ] + } + } + } + } +} \ 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..46fafa7bb93 --- /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 + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(new LineString { 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..f10d34a2c3d --- /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": { + "type": "multilinestring", + "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 ] ] + ] + } + } + } + } +} 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..edf112eae75 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineStringJson.cs @@ -0,0 +1,38 @@ +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 + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(new MultiLineString + { + 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..94e7b00adc5 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPoint.json @@ -0,0 +1,16 @@ + { + "from": 0, + "size": 10, + "query": { + "geo_shape": { + "myGeoShape": { + "shape": { + "type": "multipoint", + "coordinates": [ + [ 13.0, 53.0 ], [ 14.0, 52.0 ] + ] + } + } + } + } +} \ No newline at end of file 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..a06fbbf9093 --- /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 + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(new MultiPoint { 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..7d7ba713079 --- /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": { + "type": "multipolygon", + "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 ] ] + ] + ] + } + } + } + } +} 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..8caecab8c98 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygonJson.cs @@ -0,0 +1,50 @@ +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 + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(new MultiPolygon + { + 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..114ea39a353 --- /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": { + "type": "point", + "coordinates": [ -45.0, 45.0 ] + } + } + } + } +} 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..3e7594db67e --- /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 + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(new Point { 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..ad4b309ad66 --- /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": { + "type": "polygon", + "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 ] ] + ] + } + } + } + } +} 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..c6e338382e0 --- /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 Polygon + { + 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 + .GeoShape(qs => qs + .OnField(p => p.MyGeoShape) + .Shape(polygon) + ) + ); + + this.JsonEquals(s, MethodInfo.GetCurrentMethod()); + } + } +} From 6294d32f717ea70fb80d1d22ba3aa05806a1fdbe Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 14 Jul 2014 13:36:14 -0400 Subject: [PATCH 02/14] Fix indexed geo shape Field property serialization --- src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs | 8 ++++---- .../DSL/{GeoIndexedShapeVector.cs => GeoIndexedShape.cs} | 6 +++--- src/Nest/Nest.csproj | 2 +- .../Converters/Filters/GeoShapeFilterJsonReader.cs | 4 ++-- .../Search/Filter/Singles/GeoIndexedShapeFilterJson.cs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) rename src/Nest/Domain/DSL/{GeoIndexedShapeVector.cs => GeoIndexedShape.cs} (79%) diff --git a/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs index 6f8dbc9644a..191e04154af 100644 --- a/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs +++ b/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs @@ -16,7 +16,7 @@ public interface IGeoIndexedShapeFilter : IGeoShapeBaseFilter { [JsonProperty("indexed_shape")] - GeoIndexedShapeVector IndexedShape { get; set; } + GeoIndexedShape IndexedShape { get; set; } } public class GeoIndexedShapeFilter : PlainFilter, IGeoIndexedShapeFilter @@ -28,7 +28,7 @@ protected internal override void WrapInContainer(IFilterContainer container) public PropertyPathMarker Field { get; set; } - public GeoIndexedShapeVector IndexedShape { get; set; } + public GeoIndexedShape IndexedShape { get; set; } } public class GeoIndexedShapeFilterDescriptor : FilterBase, IGeoIndexedShapeFilter @@ -43,7 +43,7 @@ bool IFilter.IsConditionless } PropertyPathMarker IFieldNameFilter.Field { get; set; } - GeoIndexedShapeVector IGeoIndexedShapeFilter.IndexedShape { get; set; } + GeoIndexedShape IGeoIndexedShapeFilter.IndexedShape { get; set; } public GeoIndexedShapeFilterDescriptor Lookup(string field, string id, string index = null, string type = null) { @@ -52,7 +52,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 GeoIndexedShape { Field = field, Id = id, diff --git a/src/Nest/Domain/DSL/GeoIndexedShapeVector.cs b/src/Nest/Domain/DSL/GeoIndexedShape.cs similarity index 79% rename from src/Nest/Domain/DSL/GeoIndexedShapeVector.cs rename to src/Nest/Domain/DSL/GeoIndexedShape.cs index 8e99d4db521..bf55f7d3846 100644 --- a/src/Nest/Domain/DSL/GeoIndexedShapeVector.cs +++ b/src/Nest/Domain/DSL/GeoIndexedShape.cs @@ -4,10 +4,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 GeoIndexedShape { [JsonProperty("id")] public string Id { get; set; } @@ -18,7 +18,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/Nest.csproj b/src/Nest/Nest.csproj index caa81f50236..11f9eceec34 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -369,7 +369,7 @@ - + diff --git a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs index 2618787d4de..90f12822383 100644 --- a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs +++ b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs @@ -63,11 +63,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist else if (indexedShape != null) { IGeoIndexedShapeFilter f = new GeoIndexedShapeFilterDescriptor(); - f.IndexedShape = new GeoIndexedShapeVector(); + f.IndexedShape = new GeoIndexedShape(); 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/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, From 0db09c8f6f3b51e6d98989b0c789c695cc209930 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 12:44:09 -0400 Subject: [PATCH 03/14] Refactor GeoShape implementation into sub interfaces and separate descriptors --- src/Nest/DSL/Filter/FilterDescriptor.cs | 194 +++++++++++++++++- .../Filter/GeoIndexedShapeFilterDescriptor.cs | 8 +- .../Filter/GeoShapeCircleFilterDescriptor.cs | 56 +++++ .../GeoShapeEnvelopeFilterDescriptor.cs | 61 ++++++ .../DSL/Filter/GeoShapeFilterDescriptor.cs | 58 ------ .../GeoShapeLineStringFilterDescriptor.cs | 56 +++++ ...GeoShapeMultiLineStringFilterDescriptor.cs | 56 +++++ .../GeoShapeMultiPointFilterDescriptor.cs | 56 +++++ .../GeoShapeMultiPolygonFilterDescriptor.cs | 56 +++++ .../Filter/GeoShapePointFilterDescriptor.cs | 56 +++++ .../Filter/GeoShapePolygonFilterDescriptor.cs | 56 +++++ src/Nest/DSL/Filter/IFilterContainer.cs | 2 +- .../Query/GeoShapeCircleQueryDescriptor.cs | 101 +++++++++ .../Query/GeoShapeEnvelopeQueryDescriptor.cs | 87 ++++++++ .../GeoShapeLineStringQueryDescriptor.cs | 86 ++++++++ .../GeoShapeMultiLineStringQueryDescriptor.cs | 86 ++++++++ .../GeoShapeMultiPointQueryDescriptor.cs | 86 ++++++++ .../GeoShapeMultiPolygonQueryDescriptor.cs | 86 ++++++++ .../DSL/Query/GeoShapePointQueryDescriptor.cs | 86 ++++++++ .../Query/GeoShapePolygonQueryDescriptor.cs | 88 ++++++++ src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs | 89 -------- src/Nest/DSL/Query/IQueryContainer.cs | 2 +- src/Nest/DSL/Query/QueryDescriptor.cs | 53 ++++- src/Nest/Domain/DSL/GeoShape.cs | 24 --- src/Nest/Domain/DSL/Query.cs | 32 ++- src/Nest/Domain/Geometry/Circle.cs | 28 --- src/Nest/Domain/Geometry/CircleGeoShape.cs | 32 +++ src/Nest/Domain/Geometry/Envelope.cs | 19 -- src/Nest/Domain/Geometry/EnvelopeGeoShape.cs | 27 +++ src/Nest/Domain/Geometry/GeoShape.cs | 24 +++ src/Nest/Domain/Geometry/GeometryObject.cs | 31 --- src/Nest/Domain/Geometry/IGeometryObject.cs | 14 -- .../IndexedGeoShape.cs} | 2 +- src/Nest/Domain/Geometry/LineString.cs | 19 -- .../Domain/Geometry/LineStringGeoShape.cs | 27 +++ src/Nest/Domain/Geometry/MultiLineString.cs | 19 -- .../Geometry/MultiLineStringGeoShape.cs | 27 +++ src/Nest/Domain/Geometry/MultiPoint.cs | 19 -- .../Domain/Geometry/MultiPointGeoShape.cs | 27 +++ src/Nest/Domain/Geometry/MultiPolygon.cs | 19 -- .../Domain/Geometry/MultiPolygonGeoShape.cs | 27 +++ src/Nest/Domain/Geometry/Point.cs | 19 -- src/Nest/Domain/Geometry/PointGeoShape.cs | 27 +++ src/Nest/Domain/Geometry/Polygon.cs | 19 -- src/Nest/Domain/Geometry/PolygonGeoShape.cs | 27 +++ src/Nest/Nest.csproj | 41 ++-- .../Filters/GeoShapeFilterJsonReader.cs | 96 ++++++++- .../Queries/GeoShapeQueryConverter.cs | 28 +++ .../Filter/GeoShapeFilterTests.cs | 11 +- .../Queries/GeoShapeQueryTests.cs | 13 +- .../Filter/Singles/GeoShapeFilterJson.cs | 8 +- .../Singles/GeoShape/GeoShapeCircleJson.cs | 5 +- .../Singles/GeoShape/GeoShapeEnvelope.json | 4 +- .../Singles/GeoShape/GeoShapeEnvelopeJson.cs | 4 +- .../GeoShape/GeoShapeLineStringJson.cs | 4 +- .../GeoShape/GeoShapeMultiLineStringJson.cs | 13 +- .../GeoShape/GeoShapeMultiPointJson.cs | 4 +- .../GeoShape/GeoShapeMultiPolygonJson.cs | 11 +- .../Singles/GeoShape/GeoShapePointJson.cs | 4 +- .../Singles/GeoShape/GeoShapePolygonJson.cs | 6 +- 60 files changed, 1859 insertions(+), 467 deletions(-) create mode 100644 src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs create mode 100644 src/Nest/DSL/Filter/GeoShapeEnvelopeFilterDescriptor.cs delete mode 100644 src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs create mode 100644 src/Nest/DSL/Filter/GeoShapeLineStringFilterDescriptor.cs create mode 100644 src/Nest/DSL/Filter/GeoShapeMultiLineStringFilterDescriptor.cs create mode 100644 src/Nest/DSL/Filter/GeoShapeMultiPointFilterDescriptor.cs create mode 100644 src/Nest/DSL/Filter/GeoShapeMultiPolygonFilterDescriptor.cs create mode 100644 src/Nest/DSL/Filter/GeoShapePointFilterDescriptor.cs create mode 100644 src/Nest/DSL/Filter/GeoShapePolygonFilterDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapeCircleQueryDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapeEnvelopeQueryDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapeLineStringQueryDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapeMultiLineStringQueryDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapeMultiPointQueryDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapeMultiPolygonQueryDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapePointQueryDescriptor.cs create mode 100644 src/Nest/DSL/Query/GeoShapePolygonQueryDescriptor.cs delete mode 100644 src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs delete mode 100644 src/Nest/Domain/DSL/GeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/Circle.cs create mode 100644 src/Nest/Domain/Geometry/CircleGeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/Envelope.cs create mode 100644 src/Nest/Domain/Geometry/EnvelopeGeoShape.cs create mode 100644 src/Nest/Domain/Geometry/GeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/GeometryObject.cs delete mode 100644 src/Nest/Domain/Geometry/IGeometryObject.cs rename src/Nest/Domain/{DSL/GeoIndexedShape.cs => Geometry/IndexedGeoShape.cs} (94%) delete mode 100644 src/Nest/Domain/Geometry/LineString.cs create mode 100644 src/Nest/Domain/Geometry/LineStringGeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/MultiLineString.cs create mode 100644 src/Nest/Domain/Geometry/MultiLineStringGeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/MultiPoint.cs create mode 100644 src/Nest/Domain/Geometry/MultiPointGeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/MultiPolygon.cs create mode 100644 src/Nest/Domain/Geometry/MultiPolygonGeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/Point.cs create mode 100644 src/Nest/Domain/Geometry/PointGeoShape.cs delete mode 100644 src/Nest/Domain/Geometry/Polygon.cs create mode 100644 src/Nest/Domain/Geometry/PolygonGeoShape.cs create mode 100644 src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs diff --git a/src/Nest/DSL/Filter/FilterDescriptor.cs b/src/Nest/DSL/Filter/FilterDescriptor.cs index 9980547ab7d..efdcab071eb 100644 --- a/src/Nest/DSL/Filter/FilterDescriptor.cs +++ b/src/Nest/DSL/Filter/FilterDescriptor.cs @@ -261,26 +261,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 191e04154af..2472d21cfd7 100644 --- a/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs +++ b/src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs @@ -16,7 +16,7 @@ public interface IGeoIndexedShapeFilter : IGeoShapeBaseFilter { [JsonProperty("indexed_shape")] - GeoIndexedShape IndexedShape { get; set; } + IndexedGeoShape IndexedShape { get; set; } } public class GeoIndexedShapeFilter : PlainFilter, IGeoIndexedShapeFilter @@ -28,7 +28,7 @@ protected internal override void WrapInContainer(IFilterContainer container) public PropertyPathMarker Field { get; set; } - public GeoIndexedShape IndexedShape { get; set; } + public IndexedGeoShape IndexedShape { get; set; } } public class GeoIndexedShapeFilterDescriptor : FilterBase, IGeoIndexedShapeFilter @@ -43,7 +43,7 @@ bool IFilter.IsConditionless } PropertyPathMarker IFieldNameFilter.Field { get; set; } - GeoIndexedShape IGeoIndexedShapeFilter.IndexedShape { get; set; } + IndexedGeoShape IGeoIndexedShapeFilter.IndexedShape { get; set; } public GeoIndexedShapeFilterDescriptor Lookup(string field, string id, string index = null, string type = null) { @@ -52,7 +52,7 @@ public GeoIndexedShapeFilterDescriptor Lookup(string field, string id, string private GeoIndexedShapeFilterDescriptor _SetShape(PropertyPathMarker field, string id, string index, string type) { - ((IGeoIndexedShapeFilter)this).IndexedShape = new GeoIndexedShape + ((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..0ac0931d239 --- /dev/null +++ b/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.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 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; + } + } + +} 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 9cd14607ecc..00000000000 --- a/src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs +++ /dev/null @@ -1,58 +0,0 @@ -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 - { - } - - public interface IGeoShapeFilter : IGeoShapeBaseFilter - { - [JsonProperty("shape")] - GeoShape Shape { get; set; } - } - - public class GeoShapeFilter : PlainFilter, IGeoShapeFilter - { - protected internal override void WrapInContainer(IFilterContainer container) - { - container.GeoShape = this; - } - - public PropertyPathMarker Field { get; set; } - - public GeoShape Shape { get; set; } - } - - public class GeoShapeFilterDescriptor : FilterBase, IGeoShapeFilter - { - IGeoShapeFilter Self { get { return this; } } - - bool IFilter.IsConditionless - { - get - { - return this.Self.Shape == null; - } - } - - PropertyPathMarker IFieldNameFilter.Field { get; set; } - GeoShape IGeoShapeFilter.Shape { get; set; } - - public GeoShapeFilterDescriptor Shape(IGeometryObject shape) - { - this.Self.Shape = shape.ToGeoShape(); - 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 d40472c26c4..ebefc033592 100644 --- a/src/Nest/DSL/Filter/IFilterContainer.cs +++ b/src/Nest/DSL/Filter/IFilterContainer.cs @@ -60,7 +60,7 @@ public interface IFilterContainer IGeoPolygonFilter GeoPolygon { get; set; } [JsonProperty(PropertyName = "geo_shape")] - [JsonConverter(typeof(CompositeJsonConverter>))] + [JsonConverter(typeof(GeoShapeFilterJsonReader))] IGeoShapeBaseFilter GeoShape { get; set; } [JsonProperty(PropertyName = "limit")] diff --git a/src/Nest/DSL/Query/GeoShapeCircleQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeCircleQueryDescriptor.cs new file mode 100644 index 00000000000..23009540374 --- /dev/null +++ b/src/Nest/DSL/Query/GeoShapeCircleQueryDescriptor.cs @@ -0,0 +1,101 @@ +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 IGeoShapeQuery : IFieldNameQuery + { + PropertyPathMarker Field { get; set; } + } + + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IGeoShapeCircleQuery : IGeoShapeQuery + { + [JsonProperty("shape")] + ICircleGeoShape Shape { get; set; } + } + + public class GeoShapeCircleQuery : PlainQuery, IGeoShapeCircleQuery + { + 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 ICircleGeoShape Shape { get; set; } + } + + public class GeoShapeCircleQueryDescriptor : IGeoShapeCircleQuery where T : class + { + PropertyPathMarker IGeoShapeQuery.Field { get; set; } + + ICircleGeoShape IGeoShapeCircleQuery.Shape { get; set; } + + bool IQuery.IsConditionless + { + get + { + return ((IGeoShapeQuery)this).Field.IsConditionless() || ((IGeoShapeCircleQuery)this).Shape == null || !((IGeoShapeCircleQuery)this).Shape.Coordinates.HasAny(); + } + + } + void IFieldNameQuery.SetFieldName(string fieldName) + { + ((IGeoShapeQuery)this).Field = fieldName; + } + PropertyPathMarker IFieldNameQuery.GetFieldName() + { + return ((IGeoShapeQuery)this).Field; + } + + public GeoShapeCircleQueryDescriptor OnField(string field) + { + ((IGeoShapeQuery)this).Field = field; + return this; + } + + public GeoShapeCircleQueryDescriptor OnField(Expression> objectPath) + { + ((IGeoShapeQuery)this).Field = objectPath; + return this; + } + + public GeoShapeCircleQueryDescriptor Coordinates(IEnumerable coordinates) + { + if (((IGeoShapeCircleQuery)this).Shape == null) + ((IGeoShapeCircleQuery)this).Shape = new CircleGeoShape(); + ((IGeoShapeCircleQuery)this).Shape.Coordinates = coordinates; + return this; + } + + public GeoShapeCircleQueryDescriptor Radius(string radius) + { + 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/GeoShapeQueryDescriptor.cs b/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs deleted file mode 100644 index 9e06311534f..00000000000 --- a/src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs +++ /dev/null @@ -1,89 +0,0 @@ -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 IGeoShapeQuery : IFieldNameQuery - { - PropertyPathMarker Field { get; set; } - - [JsonProperty("shape")] - GeoShape Shape { get; set; } - } - - public class GeoShapeQuery : PlainQuery, IGeoShapeQuery - { - 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 GeoShape Shape { get; set; } - } - - public class GeoShapeQueryDescriptor : IGeoShapeQuery where T : class - { - IGeoShapeQuery Self { get { return this; } } - - PropertyPathMarker IGeoShapeQuery.Field { get; set; } - - GeoShape IGeoShapeQuery.Shape { get; set; } - - bool IQuery.IsConditionless - { - get - { - return this.Self.Field.IsConditionless() || this.Self.Shape == null; - } - - } - void IFieldNameQuery.SetFieldName(string fieldName) - { - this.Self.Field = fieldName; - } - PropertyPathMarker IFieldNameQuery.GetFieldName() - { - return this.Self.Field; - } - - public GeoShapeQueryDescriptor OnField(string field) - { - this.Self.Field = field; - return this; - } - public GeoShapeQueryDescriptor OnField(Expression> objectPath) - { - this.Self.Field = objectPath; - return this; - } - - public GeoShapeQueryDescriptor Shape(IGeometryObject shape) - { - shape.ThrowIfNull("shape"); - this.Self.Shape = shape.ToGeoShape(); - return this; - } - } -} diff --git a/src/Nest/DSL/Query/IQueryContainer.cs b/src/Nest/DSL/Query/IQueryContainer.cs index 5ed243eb1c0..6ef56fd48ca 100644 --- a/src/Nest/DSL/Query/IQueryContainer.cs +++ b/src/Nest/DSL/Query/IQueryContainer.cs @@ -74,7 +74,7 @@ public interface IQueryContainer : ICustomJson IFuzzyQuery Fuzzy { get; set; } [JsonProperty(PropertyName = "geo_shape")] - [JsonConverter(typeof (FieldNameQueryConverter>))] + [JsonConverter(typeof(GeoShapeQueryConverter))] IGeoShapeQuery GeoShape { get; set; } [JsonProperty(PropertyName = "common_terms")] diff --git a/src/Nest/DSL/Query/QueryDescriptor.cs b/src/Nest/DSL/Query/QueryDescriptor.cs index 045e20efb82..8d266ea33c7 100644 --- a/src/Nest/DSL/Query/QueryDescriptor.cs +++ b/src/Nest/DSL/Query/QueryDescriptor.cs @@ -319,13 +319,62 @@ public QueryContainer MoreLikeThis(Action> select /// that have a shape that intersects with the query 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); } + public QueryContainer GeoShapeCircle(Action> selector) + { + var query = new GeoShapeCircleQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + public QueryContainer GeoShapeLineString(Action> selector) + { + var query = new GeoShapeLineStringQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + public QueryContainer GeoShapeMultiLineString(Action> selector) + { + var query = new GeoShapeMultiLineStringQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + public QueryContainer GeoShapePoint(Action> selector) + { + var query = new GeoShapePointQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + public QueryContainer GeoShapeMultiPoint(Action> selector) + { + var query = new GeoShapeMultiPointQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + public QueryContainer GeoShapePolygon(Action> selector) + { + var query = new GeoShapePolygonQueryDescriptor(); + selector(query); + return this.New(query, q => q.GeoShape = query); + } + + 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/GeoShape.cs b/src/Nest/Domain/DSL/GeoShape.cs deleted file mode 100644 index 86333732633..00000000000 --- a/src/Nest/Domain/DSL/GeoShape.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json; - -namespace Nest -{ - /// - /// An object to describe a geoshape - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html - /// - public class GeoShape - { - [JsonProperty("type")] - public string Type { get; set; } - - [JsonProperty("coordinates")] - public object Coordinates { get; set; } - - [JsonProperty("radius")] - public string Radius { get; set; } - } -} diff --git a/src/Nest/Domain/DSL/Query.cs b/src/Nest/Domain/DSL/Query.cs index d7f2b84f09d..c6b7bc3423c 100644 --- a/src/Nest/Domain/DSL/Query.cs +++ b/src/Nest/Domain/DSL/Query.cs @@ -138,9 +138,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/Circle.cs b/src/Nest/Domain/Geometry/Circle.cs deleted file mode 100644 index d5be0c882f0..00000000000 --- a/src/Nest/Domain/Geometry/Circle.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class Circle - : GeometryObject> - { - public Circle() : this(null) { } - - public Circle(IEnumerable coordinates) - : base("circle") - { - this.Coordinates = coordinates ?? new List(); - } - - public string Radius { get; set; } - - public override GeoShape ToGeoShape() - { - var shape = base.ToGeoShape(); - shape.Radius = this.Radius; - return shape; - } - } -} 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/Envelope.cs b/src/Nest/Domain/Geometry/Envelope.cs deleted file mode 100644 index 0145ec88575..00000000000 --- a/src/Nest/Domain/Geometry/Envelope.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class Envelope - : GeometryObject>> - { - public Envelope() : this(null) { } - - public Envelope(IEnumerable> coordinates) - : base("envelope") - { - this.Coordinates = coordinates ?? new List>(); - } - } -} 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/Geometry/GeometryObject.cs b/src/Nest/Domain/Geometry/GeometryObject.cs deleted file mode 100644 index c329e2defa0..00000000000 --- a/src/Nest/Domain/Geometry/GeometryObject.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public abstract class GeometryObject - : IGeometryObject - { - public GeometryObject(string type) - { - this.Type = type; - } - - public string Type { get; protected set; } - - public TCoordinates Coordinates { get; set; } - - public virtual GeoShape ToGeoShape() - { - var shape = new GeoShape - { - Type = this.Type, - Coordinates = this.Coordinates - }; - - return shape; - } - } -} diff --git a/src/Nest/Domain/Geometry/IGeometryObject.cs b/src/Nest/Domain/Geometry/IGeometryObject.cs deleted file mode 100644 index d0700108663..00000000000 --- a/src/Nest/Domain/Geometry/IGeometryObject.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public interface IGeometryObject - { - string Type { get; } - TCoordinates Coordinates { get; set; } - GeoShape ToGeoShape(); - } -} diff --git a/src/Nest/Domain/DSL/GeoIndexedShape.cs b/src/Nest/Domain/Geometry/IndexedGeoShape.cs similarity index 94% rename from src/Nest/Domain/DSL/GeoIndexedShape.cs rename to src/Nest/Domain/Geometry/IndexedGeoShape.cs index bf55f7d3846..cb74409c25c 100644 --- a/src/Nest/Domain/DSL/GeoIndexedShape.cs +++ b/src/Nest/Domain/Geometry/IndexedGeoShape.cs @@ -7,7 +7,7 @@ namespace Nest /// An object to describe an indexed geoshape /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html /// - public class GeoIndexedShape + public class IndexedGeoShape { [JsonProperty("id")] public string Id { get; set; } diff --git a/src/Nest/Domain/Geometry/LineString.cs b/src/Nest/Domain/Geometry/LineString.cs deleted file mode 100644 index e6bd8bd3459..00000000000 --- a/src/Nest/Domain/Geometry/LineString.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class LineString - : GeometryObject>> - { - public LineString() : this(null) { } - - public LineString(IEnumerable> coordinates) - : base("linestring") - { - this.Coordinates = coordinates ?? new List>(); - } - } -} 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/MultiLineString.cs b/src/Nest/Domain/Geometry/MultiLineString.cs deleted file mode 100644 index 5ca17961275..00000000000 --- a/src/Nest/Domain/Geometry/MultiLineString.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class MultiLineString - : GeometryObject>>> - { - public MultiLineString() : this(null) { } - - public MultiLineString(IEnumerable>> coordinates) - : base("multilinestring") - { - this.Coordinates = coordinates ?? new List>>(); - } - } -} 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/MultiPoint.cs b/src/Nest/Domain/Geometry/MultiPoint.cs deleted file mode 100644 index 1ad8f3ac44c..00000000000 --- a/src/Nest/Domain/Geometry/MultiPoint.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class MultiPoint : - GeometryObject>> - { - public MultiPoint() : this(null) { } - - public MultiPoint(IEnumerable> coordinates) - : base("multipoint") - { - this.Coordinates = coordinates ?? new List>(); - } - } -} 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/MultiPolygon.cs b/src/Nest/Domain/Geometry/MultiPolygon.cs deleted file mode 100644 index 96c23e60c93..00000000000 --- a/src/Nest/Domain/Geometry/MultiPolygon.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class MultiPolygon - : GeometryObject>>>> - { - public MultiPolygon() : this(null) { } - - public MultiPolygon(IEnumerable>>> coordinates) - : base("multipolygon") - { - this.Coordinates = coordinates ?? new List>>>(); - } - } -} 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/Point.cs b/src/Nest/Domain/Geometry/Point.cs deleted file mode 100644 index d3b426a51b8..00000000000 --- a/src/Nest/Domain/Geometry/Point.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class Point - : GeometryObject> - { - public Point() : this(null) { } - - public Point(IEnumerable coordinates) - : base("point") - { - this.Coordinates = coordinates ?? new List(); - } - } -} 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/Polygon.cs b/src/Nest/Domain/Geometry/Polygon.cs deleted file mode 100644 index d942ccafcc7..00000000000 --- a/src/Nest/Domain/Geometry/Polygon.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class Polygon : - GeometryObject< IEnumerable>>> - { - public Polygon() : this(null) { } - - public Polygon(IEnumerable>> coordinates) - : base("polygon") - { - this.Coordinates = coordinates ?? new List>>(); - } - } -} 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 11f9eceec34..c9f7c18798e 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -136,19 +136,31 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -300,7 +312,7 @@ - + @@ -369,7 +381,7 @@ - + @@ -382,7 +394,7 @@ - + @@ -664,6 +676,7 @@ + diff --git a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs index 90f12822383..c1125201156 100644 --- a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs +++ b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs @@ -49,21 +49,95 @@ 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 GeoShape(); - 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 shapeName = shape.Value(); + if (shapeName == "circle") + { + IGeoShapeCircleFilter f = new GeoShapeCircleFilterDescriptor(); + f.Shape = new CircleGeoShape(); + var radius = shape["radius"]; + if (radius != null) + f.Shape.Radius = radius.Value(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (shapeName == "envelope") + { + IGeoShapeEnvelopeFilter f = new GeoShapeEnvelopeFilterDescriptor(); + f.Shape = new EnvelopeGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (shapeName == "linestring") + { + IGeoShapeLineStringFilter f = new GeoShapeLineStringFilterDescriptor(); + f.Shape = new LineStringGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (shapeName == "multilinestring") + { + IGeoShapeMultiLineStringFilter f = new GeoShapeMultiLineStringFilterDescriptor(); + f.Shape = new MultiLineStringGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (shapeName == "point") + { + IGeoShapePointFilter f = new GeoShapePointFilterDescriptor(); + f.Shape = new PointGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (shapeName == "multipoint") + { + IGeoShapeMultiPointFilter f = new GeoShapeMultiPointFilterDescriptor(); + f.Shape = new MultiPointGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (shapeName == "polygon") + { + IGeoShapePolygonFilter f = new GeoShapePolygonFilterDescriptor(); + f.Shape = new PolygonGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (shapeName == "multipolygon") + { + IGeoShapeMultiPolygonFilter f = new GeoShapeMultiPolygonFilterDescriptor(); + f.Shape = new MultiPolygonGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } } else if (indexedShape != null) { IGeoIndexedShapeFilter f = new GeoIndexedShapeFilterDescriptor(); - f.IndexedShape = new GeoIndexedShape(); + f.IndexedShape = new IndexedGeoShape(); var id = indexedShape["id"]; var index = indexedShape["index"]; var type = indexedShape["type"]; diff --git a/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs new file mode 100644 index 00000000000..49fe67b06c9 --- /dev/null +++ b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class GeoShapeQueryConverter : JsonConverter + { + 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) + { + return null; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs b/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs index 2654ada6a7f..0562f7e24a0 100644 --- a/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs +++ b/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs @@ -13,12 +13,13 @@ public void GeoShape_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 - .Shape(new Envelope { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) - ) - ); + 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; + var geoShapeFilter = geoBaseShapeFilter as IGeoShapeEnvelopeFilter; geoShapeFilter.Should().NotBeNull(); geoShapeFilter.Shape.Should().NotBeNull(); geoShapeFilter.Shape.Type.Should().Be("envelope"); diff --git a/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs b/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs index c44157cfd77..e5c5687fc36 100644 --- a/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs +++ b/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs @@ -14,17 +14,18 @@ public void GeoShape_Deserializes() { var q = this.SerializeThenDeserialize( f => f.GeoShape, - f => f.GeoShape(gq => gq + f => f.GeoShapeEnvelope(gq => gq .OnField(p => p.MyGeoShape) - .Shape(new Envelope { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) + .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("envelope"); - //((Newtonsoft.Json.Linq.JArray)q.ShapeVector.Coordinates).SelectMany(c=>c).Should() - // .BeEquivalentTo(new [] {13.0, 53.0, 14.0, 52.0 }); + var envelopeQuery = q as IGeoShapeEnvelopeQuery; + envelopeQuery.Should().NotBeNull(); + envelopeQuery.Shape.Type.Should().Be("envelope"); + envelopeQuery.Shape.Coordinates.SelectMany(c=>c).Should() + .BeEquivalentTo(new [] {13.0, 53.0, 14.0, 52.0 }); } } } \ No newline at end of file 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 c2706047828..d9ce6a8c267 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs @@ -17,8 +17,8 @@ public void GeoShapeFilter() .Filter(filter => filter .Cache(true) .Name("my_geo_filter") - .GeoShape(f => f.Origin, d => d - .Shape(new Envelope { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) + .GeoShapeEnvelope(f => f.Origin, d => d + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) ) ); @@ -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, 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 index 060856b7303..5e3c1f517dd 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircleJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircleJson.cs @@ -19,9 +19,10 @@ public void GeoShapeCircle() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapeCircle(qs => qs .OnField(p => p.MyGeoShape) - .Shape(new Circle { Coordinates = new[] { -45.0, 45.0 }, Radius = "100m" } ) + .Coordinates(new[] { -45.0, 45.0 }) + .Radius("100m") ) ); diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelope.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelope.json index 57c5437f1d3..c76fd375a6e 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelope.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelope.json @@ -5,10 +5,10 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "envelope", "coordinates": [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] - ] + ], + "type": "envelope" } } } diff --git a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelopeJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelopeJson.cs index 5088e69d903..11e8be6b3eb 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelopeJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeEnvelopeJson.cs @@ -15,9 +15,9 @@ public void GeoShapeEnvelope() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapeEnvelope(qs => qs .OnField(p => p.MyGeoShape) - .Shape(new Envelope { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) ) ); 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 index 46fafa7bb93..e3b30722955 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineStringJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineStringJson.cs @@ -19,9 +19,9 @@ public void GeoShapeLineString() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapeLineString(qs => qs .OnField(p => p.MyGeoShape) - .Shape(new LineString { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) ) ); 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 index edf112eae75..05c1aa6c80a 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineStringJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineStringJson.cs @@ -19,18 +19,15 @@ public void GeoShapeMultiLineString() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapeMultiLineString(qs => qs .OnField(p => p.MyGeoShape) - .Shape(new MultiLineString - { - Coordinates = new[] { + .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/GeoShapeMultiPointJson.cs b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPointJson.cs index a06fbbf9093..8f62b6c11a3 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPointJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPointJson.cs @@ -19,9 +19,9 @@ public void GeoShapeMultiPoint() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapeMultiPoint(qs => qs .OnField(p => p.MyGeoShape) - .Shape(new MultiPoint { Coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } } }) + .Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } }) ) ); 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 index 8caecab8c98..e841290a060 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygonJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygonJson.cs @@ -19,11 +19,9 @@ public void GeoShapeMultiPolygon() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapeMultiPolygon(qs => qs .OnField(p => p.MyGeoShape) - .Shape(new MultiPolygon - { - Coordinates = + .Coordinates( new[] { new [] { new [] { @@ -39,10 +37,9 @@ public void GeoShapeMultiPolygon() } } } - } + ) ) - ) - ); + ); this.JsonEquals(s, MethodInfo.GetCurrentMethod()); } 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 index 3e7594db67e..4f715be5dd8 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePointJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePointJson.cs @@ -19,9 +19,9 @@ public void GeoShapePoint() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapePoint(qs => qs .OnField(p => p.MyGeoShape) - .Shape(new Point { Coordinates = new[] { -45.0, 45.0 } }) + .Coordinates(new[] { -45.0, 45.0 }) ) ); 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 index c6e338382e0..61b45c60a73 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygonJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygonJson.cs @@ -15,7 +15,7 @@ public class GeoShapePolygonJson : BaseJsonTests [Test] public void GeoShapePolygon() { - var polygon = new Polygon + 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 } }, @@ -27,9 +27,9 @@ public void GeoShapePolygon() .From(0) .Size(10) .Query(q => q - .GeoShape(qs => qs + .GeoShapePolygon(qs => qs .OnField(p => p.MyGeoShape) - .Shape(polygon) + .Coordinates(polygon.Coordinates) ) ); From ecb04b74b756ef724429f455ebd73a812deef872 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 15 Jul 2014 19:17:27 +0200 Subject: [PATCH 04/14] added compositejsonconverter to geoshapes so that they are read using the specialized geoshape writer but written using the mode generic fieldname converter --- src/Nest/DSL/Filter/IFilterContainer.cs | 2 +- src/Nest/DSL/Query/IQueryContainer.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Nest/DSL/Filter/IFilterContainer.cs b/src/Nest/DSL/Filter/IFilterContainer.cs index ebefc033592..ec1167f5080 100644 --- a/src/Nest/DSL/Filter/IFilterContainer.cs +++ b/src/Nest/DSL/Filter/IFilterContainer.cs @@ -60,7 +60,7 @@ public interface IFilterContainer IGeoPolygonFilter GeoPolygon { get; set; } [JsonProperty(PropertyName = "geo_shape")] - [JsonConverter(typeof(GeoShapeFilterJsonReader))] + [JsonConverter(typeof(CompositeJsonConverter>))] IGeoShapeBaseFilter GeoShape { get; set; } [JsonProperty(PropertyName = "limit")] diff --git a/src/Nest/DSL/Query/IQueryContainer.cs b/src/Nest/DSL/Query/IQueryContainer.cs index 6ef56fd48ca..26ecb0f7e47 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(GeoShapeQueryConverter))] + [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")] From b194da00dcf56462b9ba58ffe1107fbd9c966e53 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 13:27:25 -0400 Subject: [PATCH 05/14] Fix failing json tests (property order) --- .../Search/Query/Singles/GeoShape/GeoShapeCircle.json | 4 ++-- .../Query/Singles/GeoShape/GeoShapeLineString.json | 4 ++-- .../Query/Singles/GeoShape/GeoShapeMultiPoint.json | 11 ++++++----- .../Query/Singles/GeoShape/GeoShapeMultiPolygon.json | 4 ++-- .../Search/Query/Singles/GeoShape/GeoShapePoint.json | 4 ++-- .../Query/Singles/GeoShape/GeoShapePolygon.json | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) 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 index 1639e996397..abcc06cd16a 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircle.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeCircle.json @@ -5,9 +5,9 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "circle", "coordinates": [ -45.0, 45.0 ], - "radius": "100m" + "radius": "100m", + "type": "circle" } } } 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 index 2f2e3b87bea..b8c7a9f6cd9 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineString.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeLineString.json @@ -5,10 +5,10 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "linestring", "coordinates": [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] - ] + ], + "type": "linestring" } } } 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 index 94e7b00adc5..da9c8dbe7bf 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPoint.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPoint.json @@ -1,16 +1,17 @@ - { +{ "from": 0, "size": 10, "query": { "geo_shape": { "myGeoShape": { "shape": { - "type": "multipoint", "coordinates": [ - [ 13.0, 53.0 ], [ 14.0, 52.0 ] - ] + [ 13.0, 53.0 ], + [ 14.0, 52.0 ] + ], + "type": "multipoint" } } } } -} \ No newline at end of file +} 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 index 7d7ba713079..25a6a399224 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygon.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiPolygon.json @@ -5,14 +5,14 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "multipolygon", "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/GeoShapePoint.json b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePoint.json index 114ea39a353..e36c1aa09d2 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePoint.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePoint.json @@ -5,8 +5,8 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "point", - "coordinates": [ -45.0, 45.0 ] + "coordinates": [ -45.0, 45.0 ], + "type": "point" } } } 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 index ad4b309ad66..8735768489c 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygon.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapePolygon.json @@ -5,11 +5,11 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "polygon", "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" } } } From e549a06471ca41a36ec7610ce21c4641002b19b3 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 13:36:11 -0400 Subject: [PATCH 06/14] Fix geoshape filter json reader (parsing wrong object for type) --- .../Filters/GeoShapeFilterJsonReader.cs | 168 +++++++++--------- 1 file changed, 86 insertions(+), 82 deletions(-) diff --git a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs index c1125201156..1f8bf26ced7 100644 --- a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs +++ b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs @@ -49,89 +49,93 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var indexedShape = jv.Value["indexed_shape"]; if (shape != null) { - var shapeName = shape.Value(); - if (shapeName == "circle") + var type = shape["type"]; + if (type != null) { - IGeoShapeCircleFilter f = new GeoShapeCircleFilterDescriptor(); - f.Shape = new CircleGeoShape(); - var radius = shape["radius"]; - if (radius != null) - f.Shape.Radius = radius.Value(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; - } - else if (shapeName == "envelope") - { - IGeoShapeEnvelopeFilter f = new GeoShapeEnvelopeFilterDescriptor(); - f.Shape = new EnvelopeGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; - } - else if (shapeName == "linestring") - { - IGeoShapeLineStringFilter f = new GeoShapeLineStringFilterDescriptor(); - f.Shape = new LineStringGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; - } - else if (shapeName == "multilinestring") - { - IGeoShapeMultiLineStringFilter f = new GeoShapeMultiLineStringFilterDescriptor(); - f.Shape = new MultiLineStringGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; - } - else if (shapeName == "point") - { - IGeoShapePointFilter f = new GeoShapePointFilterDescriptor(); - f.Shape = new PointGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; - } - else if (shapeName == "multipoint") - { - IGeoShapeMultiPointFilter f = new GeoShapeMultiPointFilterDescriptor(); - f.Shape = new MultiPointGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; - } - else if (shapeName == "polygon") - { - IGeoShapePolygonFilter f = new GeoShapePolygonFilterDescriptor(); - f.Shape = new PolygonGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; - } - else if (shapeName == "multipolygon") - { - IGeoShapeMultiPolygonFilter f = new GeoShapeMultiPolygonFilterDescriptor(); - f.Shape = new MultiPolygonGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); - filter = f; - break; + var typeName = type.Value(); + if (typeName == "circle") + { + IGeoShapeCircleFilter f = new GeoShapeCircleFilterDescriptor(); + f.Shape = new CircleGeoShape(); + var radius = shape["radius"]; + if (radius != null) + f.Shape.Radius = radius.Value(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (typeName == "envelope") + { + IGeoShapeEnvelopeFilter f = new GeoShapeEnvelopeFilterDescriptor(); + f.Shape = new EnvelopeGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (typeName == "linestring") + { + IGeoShapeLineStringFilter f = new GeoShapeLineStringFilterDescriptor(); + f.Shape = new LineStringGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (typeName == "multilinestring") + { + IGeoShapeMultiLineStringFilter f = new GeoShapeMultiLineStringFilterDescriptor(); + f.Shape = new MultiLineStringGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (typeName == "point") + { + IGeoShapePointFilter f = new GeoShapePointFilterDescriptor(); + f.Shape = new PointGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (typeName == "multipoint") + { + IGeoShapeMultiPointFilter f = new GeoShapeMultiPointFilterDescriptor(); + f.Shape = new MultiPointGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (typeName == "polygon") + { + IGeoShapePolygonFilter f = new GeoShapePolygonFilterDescriptor(); + f.Shape = new PolygonGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } + else if (typeName == "multipolygon") + { + IGeoShapeMultiPolygonFilter f = new GeoShapeMultiPolygonFilterDescriptor(); + f.Shape = new MultiPolygonGeoShape(); + var coordinates = shape["coordinates"]; + if (coordinates != null) + f.Shape.Coordinates = coordinates.Values(); + filter = f; + break; + } } } else if (indexedShape != null) From 57e2cc3b7d58e5b4df59b43888a969d45aaafee8 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 13:48:00 -0400 Subject: [PATCH 07/14] Xml docs for geoshape descriptor methods --- src/Nest/DSL/Query/QueryDescriptor.cs | 39 +++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Nest/DSL/Query/QueryDescriptor.cs b/src/Nest/DSL/Query/QueryDescriptor.cs index 8d266ea33c7..ec8a5439b63 100644 --- a/src/Nest/DSL/Query/QueryDescriptor.cs +++ b/src/Nest/DSL/Query/QueryDescriptor.cs @@ -316,7 +316,7 @@ 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 GeoShapeEnvelope(Action> selector) @@ -325,7 +325,12 @@ public QueryContainer GeoShapeEnvelope(Action 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(); @@ -333,6 +338,11 @@ public QueryContainer GeoShapeCircle(Action> se 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(); @@ -340,6 +350,11 @@ public QueryContainer GeoShapeLineString(Action 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(); @@ -347,6 +362,11 @@ public QueryContainer GeoShapeMultiLineString(Action 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(); @@ -354,6 +374,11 @@ public QueryContainer GeoShapePoint(Action> sele 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(); @@ -361,6 +386,11 @@ public QueryContainer GeoShapeMultiPoint(Action 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(); @@ -368,6 +398,11 @@ public QueryContainer GeoShapePolygon(Action> 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(); From 8f31c206b8be6ce9f870bae99385e8fbd34f9b7f Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 13:55:56 -0400 Subject: [PATCH 08/14] Another json property order fix --- .../Query/Singles/GeoShape/GeoShapeMultiLineString.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index f10d34a2c3d..d3471e61e4a 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineString.json +++ b/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape/GeoShapeMultiLineString.json @@ -5,12 +5,12 @@ "geo_shape": { "myGeoShape": { "shape": { - "type": "multilinestring", "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" } } } From 26b696785d78dfa17adcbf9de4dc853531d1c116 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 15:56:22 -0400 Subject: [PATCH 09/14] Implementation of geo shape query json reader --- src/Nest/DSL/Query/IQueryContainer.cs | 2 +- src/Nest/Nest.csproj | 2 +- .../Queries/GeoShapeQueryConverter.cs | 28 ---- .../Queries/GeoShapeQueryJsonReader.cs | 121 ++++++++++++++++++ 4 files changed, 123 insertions(+), 30 deletions(-) delete mode 100644 src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs create mode 100644 src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs diff --git a/src/Nest/DSL/Query/IQueryContainer.cs b/src/Nest/DSL/Query/IQueryContainer.cs index 26ecb0f7e47..c2d1e0175d3 100644 --- a/src/Nest/DSL/Query/IQueryContainer.cs +++ b/src/Nest/DSL/Query/IQueryContainer.cs @@ -74,7 +74,7 @@ public interface IQueryContainer : ICustomJson IFuzzyQuery Fuzzy { get; set; } [JsonProperty(PropertyName = "geo_shape")] - [JsonConverter(typeof(CompositeJsonConverter>))] + [JsonConverter(typeof(CompositeJsonConverter>))] IGeoShapeQuery GeoShape { get; set; } [JsonProperty(PropertyName = "common_terms")] diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index c9f7c18798e..1b4a058b60f 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -676,7 +676,7 @@ - + diff --git a/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs deleted file mode 100644 index 49fe67b06c9..00000000000 --- a/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryConverter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nest -{ - public class GeoShapeQueryConverter : JsonConverter - { - 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) - { - return null; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - } - } -} diff --git a/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs new file mode 100644 index 00000000000..86eea4fcf89 --- /dev/null +++ b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs @@ -0,0 +1,121 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public class GeoShapeQueryJsonReader : JsonConverter + { + 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; + } + + private T GetCoordinates(JToken shape) + { + var coordinates = shape["coordinates"]; + if (coordinates != null) + return coordinates.ToObject(); + return default(T); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + } + } +} From a24abe902feebda85e3797aa00c9d5792887e8ba Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 16:36:39 -0400 Subject: [PATCH 10/14] Full serialize => deserialize test coverage for geo shape queries --- .../Queries/GeoShapeQueryTests.cs | 191 +++++++++++++++++- 1 file changed, 185 insertions(+), 6 deletions(-) diff --git a/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs b/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs index e5c5687fc36..d8af697e4c5 100644 --- a/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs +++ b/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs @@ -10,7 +10,7 @@ public class GeoShapeQueryTests : ParseQueryTestsBase { [Test] - public void GeoShape_Deserializes() + public void GeoShapeEnvelope_Deserializes() { var q = this.SerializeThenDeserialize( f => f.GeoShape, @@ -20,12 +20,191 @@ public void GeoShape_Deserializes() ) ); - q.Field.Should().Be("myGeoShape"); - var envelopeQuery = q as IGeoShapeEnvelopeQuery; - envelopeQuery.Should().NotBeNull(); - envelopeQuery.Shape.Type.Should().Be("envelope"); - envelopeQuery.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 From cc32835f640f3a3ddd2a7963ea810bbd6179c6c4 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 16:47:56 -0400 Subject: [PATCH 11/14] Add Radius() to circle geo shape filter descriptor --- src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs b/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs index 0ac0931d239..1ef78fbb6a1 100644 --- a/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs +++ b/src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs @@ -51,6 +51,14 @@ public GeoShapeCircleFilterDescriptor Coordinates(IEnumerable coordinate 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; + } } } From bbc08615a47ed0cc82f0972a862818148db2a36a Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 17:08:38 -0400 Subject: [PATCH 12/14] Full json test coverage for geo shape filters --- .../Filter/Singles/GeoShapeFilterJson.cs | 260 +++++++++++++++++- 1 file changed, 258 insertions(+), 2 deletions(-) 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 d9ce6a8c267..bf9b484fe2a 100644 --- a/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs +++ b/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs @@ -8,7 +8,7 @@ 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() @@ -40,9 +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); } } } From 5d419fe304bfc7a53498ebc856a5746739c30f21 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 18:13:27 -0400 Subject: [PATCH 13/14] Base class for geoshape filter and query converters --- src/Nest/Nest.csproj | 1 + .../Filters/GeoShapeFilterJsonReader.cs | 34 +++++-------------- .../Converters/GeoShapeConverterBase.cs | 20 +++++++++++ .../Queries/GeoShapeQueryJsonReader.cs | 13 ++----- 4 files changed, 33 insertions(+), 35 deletions(-) create mode 100644 src/Nest/Resolvers/Converters/GeoShapeConverterBase.cs diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index 1b4a058b60f..ff0863294bd 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -676,6 +676,7 @@ + diff --git a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs index 1f8bf26ced7..ae9180c4fdb 100644 --- a/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs +++ b/src/Nest/Resolvers/Converters/Filters/GeoShapeFilterJsonReader.cs @@ -8,7 +8,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; } } @@ -57,12 +57,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { 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(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); filter = f; break; } @@ -70,9 +68,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { IGeoShapeEnvelopeFilter f = new GeoShapeEnvelopeFilterDescriptor(); f.Shape = new EnvelopeGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); + f.Shape.Coordinates = GetCoordinates>>(shape); filter = f; break; } @@ -80,9 +76,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { IGeoShapeLineStringFilter f = new GeoShapeLineStringFilterDescriptor(); f.Shape = new LineStringGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); + f.Shape.Coordinates = GetCoordinates>>(shape); filter = f; break; } @@ -90,9 +84,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { IGeoShapeMultiLineStringFilter f = new GeoShapeMultiLineStringFilterDescriptor(); f.Shape = new MultiLineStringGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); + f.Shape.Coordinates = GetCoordinates>>>(shape); filter = f; break; } @@ -100,9 +92,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { IGeoShapePointFilter f = new GeoShapePointFilterDescriptor(); f.Shape = new PointGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); + f.Shape.Coordinates = GetCoordinates>(shape); filter = f; break; } @@ -110,9 +100,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { IGeoShapeMultiPointFilter f = new GeoShapeMultiPointFilterDescriptor(); f.Shape = new MultiPointGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); + f.Shape.Coordinates = GetCoordinates>>(shape); filter = f; break; } @@ -120,9 +108,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { IGeoShapePolygonFilter f = new GeoShapePolygonFilterDescriptor(); f.Shape = new PolygonGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); + f.Shape.Coordinates = GetCoordinates>>>(shape); filter = f; break; } @@ -130,9 +116,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { IGeoShapeMultiPolygonFilter f = new GeoShapeMultiPolygonFilterDescriptor(); f.Shape = new MultiPolygonGeoShape(); - var coordinates = shape["coordinates"]; - if (coordinates != null) - f.Shape.Coordinates = coordinates.Values(); + f.Shape.Coordinates = GetCoordinates>>>>(shape); filter = f; break; } 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 index 86eea4fcf89..07b569a61e8 100644 --- a/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs +++ b/src/Nest/Resolvers/Converters/Queries/GeoShapeQueryJsonReader.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Nest.Resolvers.Converters; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -7,7 +8,7 @@ namespace Nest { - public class GeoShapeQueryJsonReader : JsonConverter + public class GeoShapeQueryJsonReader : GeoShapeConverterBase { public override bool CanConvert(Type objectType) { @@ -106,14 +107,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return query; } - private T GetCoordinates(JToken shape) - { - var coordinates = shape["coordinates"]; - if (coordinates != null) - return coordinates.ToObject(); - return default(T); - } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { } From 4addb1ecf9259a2a9855fa1335ebae3b7817e1e0 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Tue, 15 Jul 2014 18:14:25 -0400 Subject: [PATCH 14/14] Full serialize => deserialize test coverage for geoshape filters --- .../Filter/GeoShapeFilterTests.cs | 198 +++++++++++++++++- 1 file changed, 191 insertions(+), 7 deletions(-) diff --git a/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs b/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs index 0562f7e24a0..ccab812dc37 100644 --- a/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs +++ b/src/Tests/Nest.Tests.Unit/QueryParsers/Filter/GeoShapeFilterTests.cs @@ -1,6 +1,7 @@ using FluentAssertions; using NUnit.Framework; using System.Collections.Generic; +using System.Linq; namespace Nest.Tests.Unit.QueryParsers.Filter { @@ -9,7 +10,7 @@ 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, @@ -18,12 +19,195 @@ public void GeoShape_Deserializes(string cacheName, string cacheKey, bool cache) ) ); - geoBaseShapeFilter.Field.Should().Be("origin"); - var geoShapeFilter = geoBaseShapeFilter as IGeoShapeEnvelopeFilter; - 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