Skip to content

Fix/geoshape #788

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 185 additions & 9 deletions src/Nest/DSL/Filter/FilterDescriptor.cs
Original file line number Diff line number Diff line change
@@ -257,26 +257,202 @@ private FilterContainer _GeoDistanceRange(PropertyPathMarker field, Action<GeoDi
}

/// <summary>
/// Filter documents indexed using the geo_shape type.
/// Filter documents indexed using the circle geo_shape type.
/// </summary>
public FilterContainer GeoShape(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapeFilterDescriptor> filterDescriptor)
public FilterContainer GeoShapeCircle(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapeCircleFilterDescriptor> filterDescriptor)
{
return _GeoShape(fieldDescriptor, filterDescriptor);
return _GeoShapeCircle(fieldDescriptor, filterDescriptor);
}
/// <summary>
/// Filter documents indexed using the geo_shape type.
/// Filter documents indexed using the circle geo_shape type.
/// </summary>
public FilterContainer GeoShapeCircle(string field, Action<GeoShapeCircleFilterDescriptor> filterDescriptor)
{
return _GeoShapeCircle(field, filterDescriptor);
}

private FilterContainer _GeoShapeCircle(PropertyPathMarker field, Action<GeoShapeCircleFilterDescriptor> filterDescriptor)
{
var filter = new GeoShapeCircleFilterDescriptor();
if (filterDescriptor != null)
filterDescriptor(filter);
((IGeoShapeCircleFilter)filter).Field = field;
return this.New(filter, f => f.GeoShape = filter);
}

/// <summary>
/// Filter documents indexed using the envelope geo_shape type.
/// </summary>
public FilterContainer GeoShapeEnvelope(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapeEnvelopeFilterDescriptor> filterDescriptor)
{
return _GeoShapeEnvelope(fieldDescriptor, filterDescriptor);
}

/// <summary>
/// Filter documents indexed using the envelope geo_shape type.
/// </summary>
public FilterContainer GeoShapeEnvelope(string field, Action<GeoShapeEnvelopeFilterDescriptor> filterDescriptor)
{
return _GeoShapeEnvelope(field, filterDescriptor);
}

private FilterContainer _GeoShapeEnvelope(PropertyPathMarker field, Action<GeoShapeEnvelopeFilterDescriptor> filterDescriptor)
{
var filter = new GeoShapeEnvelopeFilterDescriptor();
if (filterDescriptor != null)
filterDescriptor(filter);
((IGeoShapeEnvelopeFilter)filter).Field = field;
return this.New(filter, f => f.GeoShape = filter);
}

/// <summary>
/// Filter documents indexed using the linestring geo_shape type.
/// </summary>
public FilterContainer GeoShapeLineString(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapeLineStringFilterDescriptor> filterDescriptor)
{
return _GeoShapeLineString(fieldDescriptor, filterDescriptor);
}

/// <summary>
/// Filter documents indexed using the linestring geo_shape type.
/// </summary>
public FilterContainer GeoShapeLineString(string field, Action<GeoShapeLineStringFilterDescriptor> filterDescriptor)
{
return _GeoShapeLineString(field, filterDescriptor);
}

private FilterContainer _GeoShapeLineString(PropertyPathMarker field, Action<GeoShapeLineStringFilterDescriptor> filterDescriptor)
{
var filter = new GeoShapeLineStringFilterDescriptor();
if (filterDescriptor != null)
filterDescriptor(filter);
((IGeoShapeLineStringFilter)filter).Field = field;
return this.New(filter, f => f.GeoShape = filter);
}

/// <summary>
/// Filter documents indexed using the multilinestring geo_shape type.
/// </summary>
public FilterContainer GeoShapeMultiLineString(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapeMultiLineStringFilterDescriptor> filterDescriptor)
{
return _GeoShapeMultiLineString(fieldDescriptor, filterDescriptor);
}

/// <summary>
/// Filter documents indexed using the multilinestring geo_shape type.
/// </summary>
public FilterContainer GeoShapeMultiLineString(string field, Action<GeoShapeMultiLineStringFilterDescriptor> filterDescriptor)
{
return _GeoShapeMultiLineString(field, filterDescriptor);
}

private FilterContainer _GeoShapeMultiLineString(PropertyPathMarker field, Action<GeoShapeMultiLineStringFilterDescriptor> filterDescriptor)
{
var filter = new GeoShapeMultiLineStringFilterDescriptor();
if (filterDescriptor != null)
filterDescriptor(filter);
((IGeoShapeMultiLineStringFilter)filter).Field = field;
return this.New(filter, f => f.GeoShape = filter);
}

/// <summary>
/// Filter documents indexed using the point geo_shape type.
/// </summary>
public FilterContainer GeoShapePoint(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapePointFilterDescriptor> filterDescriptor)
{
return _GeoShapePoint(fieldDescriptor, filterDescriptor);
}

/// <summary>
/// Filter documents indexed using the point geo_shape type.
/// </summary>
public FilterContainer GeoShapePoint(string field, Action<GeoShapePointFilterDescriptor> filterDescriptor)
{
return _GeoShapePoint(field, filterDescriptor);
}

private FilterContainer _GeoShapePoint(PropertyPathMarker field, Action<GeoShapePointFilterDescriptor> filterDescriptor)
{
var filter = new GeoShapePointFilterDescriptor();
if (filterDescriptor != null)
filterDescriptor(filter);
((IGeoShapePointFilter)filter).Field = field;
return this.New(filter, f => f.GeoShape = filter);
}

/// <summary>
/// Filter documents indexed using the multipoint geo_shape type.
/// </summary>
public FilterContainer GeoShapeMultiPoint(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapeMultiPointFilterDescriptor> filterDescriptor)
{
return _GeoShapeMultiPoint(fieldDescriptor, filterDescriptor);
}

/// <summary>
/// Filter documents indexed using the multipoint geo_shape type.
/// </summary>
public FilterContainer GeoShapeMultiPoint(string field, Action<GeoShapeMultiPointFilterDescriptor> filterDescriptor)
{
return _GeoShapeMultiPoint(field, filterDescriptor);
}

private FilterContainer _GeoShapeMultiPoint(PropertyPathMarker field, Action<GeoShapeMultiPointFilterDescriptor> filterDescriptor)
{
var filter = new GeoShapeMultiPointFilterDescriptor();
if (filterDescriptor != null)
filterDescriptor(filter);
((IGeoShapeMultiPointFilter)filter).Field = field;
return this.New(filter, f => f.GeoShape = filter);
}


/// <summary>
/// Filter documents indexed using the polygon geo_shape type.
/// </summary>
public FilterContainer GeoShapePolygon(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapePolygonFilterDescriptor> filterDescriptor)
{
return _GeoShapePolygon(fieldDescriptor, filterDescriptor);
}

/// <summary>
/// Filter documents indexed using the polygon geo_shape type.
/// </summary>
public FilterContainer GeoShapePolygon(string field, Action<GeoShapePolygonFilterDescriptor> filterDescriptor)
{
return _GeoShapePolygon(field, filterDescriptor);
}

private FilterContainer _GeoShapePolygon(PropertyPathMarker field, Action<GeoShapePolygonFilterDescriptor> filterDescriptor)
{
var filter = new GeoShapePolygonFilterDescriptor();
if (filterDescriptor != null)
filterDescriptor(filter);
((IGeoShapePolygonFilter)filter).Field = field;
return this.New(filter, f => f.GeoShape = filter);
}

/// <summary>
/// Filter documents indexed using the multipolygon geo_shape type.
/// </summary>
public FilterContainer GeoShapeMultiPolygon(Expression<Func<T, object>> fieldDescriptor, Action<GeoShapeMultiPolygonFilterDescriptor> filterDescriptor)
{
return _GeoShapeMultiPolygon(fieldDescriptor, filterDescriptor);
}

/// <summary>
/// Filter documents indexed using the multipolygon geo_shape type.
/// </summary>
public FilterContainer GeoShape(string field, Action<GeoShapeFilterDescriptor> filterDescriptor)
public FilterContainer GeoShapeMultiPolygon(string field, Action<GeoShapeMultiPolygonFilterDescriptor> filterDescriptor)
{
return _GeoShape(field, filterDescriptor);
return _GeoShapeMultiPolygon(field, filterDescriptor);
}

private FilterContainer _GeoShape(PropertyPathMarker field, Action<GeoShapeFilterDescriptor> filterDescriptor)
private FilterContainer _GeoShapeMultiPolygon(PropertyPathMarker field, Action<GeoShapeMultiPolygonFilterDescriptor> 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);
}

8 changes: 4 additions & 4 deletions src/Nest/DSL/Filter/GeoIndexedShapeFilterDescriptor.cs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ public interface IGeoIndexedShapeFilter : IGeoShapeBaseFilter
{

[JsonProperty("indexed_shape")]
GeoIndexedShapeVector IndexedShape { get; set; }
IndexedGeoShape IndexedShape { get; set; }
}

public class GeoIndexedShapeFilter : PlainFilter, IGeoIndexedShapeFilter
@@ -23,7 +23,7 @@ protected internal override void WrapInContainer(IFilterContainer container)

public PropertyPathMarker Field { get; set; }

public GeoIndexedShapeVector IndexedShape { get; set; }
public IndexedGeoShape IndexedShape { get; set; }
}

public class GeoIndexedShapeFilterDescriptor : FilterBase, IGeoIndexedShapeFilter
@@ -38,7 +38,7 @@ bool IFilter.IsConditionless
}

PropertyPathMarker IFieldNameFilter.Field { get; set; }
GeoIndexedShapeVector IGeoIndexedShapeFilter.IndexedShape { get; set; }
IndexedGeoShape IGeoIndexedShapeFilter.IndexedShape { get; set; }

public GeoIndexedShapeFilterDescriptor Lookup<T>(string field, string id, string index = null, string type = null)
{
@@ -47,7 +47,7 @@ public GeoIndexedShapeFilterDescriptor Lookup<T>(string field, string id, string

private GeoIndexedShapeFilterDescriptor _SetShape<T>(PropertyPathMarker field, string id, string index, string type)
{
((IGeoIndexedShapeFilter)this).IndexedShape = new GeoIndexedShapeVector
((IGeoIndexedShapeFilter)this).IndexedShape = new IndexedGeoShape
{
Field = field,
Id = id,
64 changes: 64 additions & 0 deletions src/Nest/DSL/Filter/GeoShapeCircleFilterDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nest.Resolvers;
using Nest.Resolvers.Converters;
using Nest.Resolvers.Converters.Filters;
using Newtonsoft.Json;
using Elasticsearch.Net;

namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public interface IGeoShapeCircleFilter : IGeoShapeBaseFilter
{
[JsonProperty("shape")]
ICircleGeoShape Shape { get; set; }
}

public class GeoShapeCircleFilter : PlainFilter, IGeoShapeCircleFilter
{
protected internal override void WrapInContainer(IFilterContainer container)
{
container.GeoShape = this;
}

public PropertyPathMarker Field { get; set; }

public ICircleGeoShape Shape { get; set; }
}

public class GeoShapeCircleFilterDescriptor : FilterBase, IGeoShapeCircleFilter
{
IGeoShapeCircleFilter Self { get { return this; } }

bool IFilter.IsConditionless
{
get
{
return this.Self.Shape == null || !this.Self.Shape.Coordinates.HasAny();
}
}

PropertyPathMarker IFieldNameFilter.Field { get; set; }
ICircleGeoShape IGeoShapeCircleFilter.Shape { get; set; }

public GeoShapeCircleFilterDescriptor Coordinates(IEnumerable<double> coordinates)
{
if (this.Self.Shape == null)
this.Self.Shape = new CircleGeoShape();
this.Self.Shape.Coordinates = coordinates;
return this;
}

public GeoShapeCircleFilterDescriptor Radius(string radius)
{
if (this.Self.Shape == null)
this.Self.Shape = new CircleGeoShape();
this.Self.Shape.Radius = radius;
return this;
}
}

}
61 changes: 61 additions & 0 deletions src/Nest/DSL/Filter/GeoShapeEnvelopeFilterDescriptor.cs
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<double>> coordinates)
{
if (this.Self.Shape == null)
this.Self.Shape = new EnvelopeGeoShape();
this.Self.Shape.Coordinates = coordinates;
return this;
}
}

}
Loading