예제 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var j = JObject.Load(reader);

            if (j == null || !j.HasValues)
            {
                return(null);
            }

            double?boost = null;
            string name  = null;

            if (j.TryGetValue("boost", out var b) && (b.Type != JTokenType.Array && b.Type != JTokenType.Object))
            {
                j.Remove("boost");
                boost = b.Value <double?>();
            }
            if (j.TryGetValue("_name", out var n) && n.Type == JTokenType.String)
            {
                j.Remove("_name");
                name = n.Value <string>();
            }
            var firstProp = j.Properties().FirstOrDefault();

            if (firstProp == null)
            {
                return(null);
            }

            var field = firstProp.Name;
            var jo    = firstProp.Value.Value <JObject>();

            if (jo == null)
            {
                return(null);
            }

            IGeoShapeQuery query = null;

            if (jo.TryGetValue("shape", out var shape))
            {
                query = ParseShapeQuery(shape, serializer);
            }
            else if (jo.TryGetValue("indexed_shape", out var indexedShape))
            {
                query = ParseIndexedShapeQuery(indexedShape);
            }

            if (query == null)
            {
                return(null);
            }
            var relation = jo["relation"]?.Value <string>().ToEnum <GeoShapeRelation>();

            query.Boost    = boost;
            query.Name     = name;
            query.Field    = field;
            query.Relation = relation;
            return(query);
        }
        private static QueryContainer SetGeoShapeQuery <T>(QueryDescriptor <T> queryDescriptor,
                                                           IGeoShapeQuery query) where T : class
        {
            var descriptor = new QueryDescriptor <T>();

            ((IQueryContainer)descriptor).IsStrict   = queryDescriptor.IsStrict;
            ((IQueryContainer)descriptor).IsVerbatim = queryDescriptor.IsVerbatim;
            ((IQueryContainer)descriptor).GeoShape   = query;

            return(descriptor);
        }
예제 #3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var j = JObject.Load(reader);

            if (j == null || !j.HasValues)
            {
                return(null);
            }

            var firstProp = j.Properties().FirstOrDefault();

            if (firstProp == null)
            {
                return(null);
            }

            var field = firstProp.Name;
            var jo    = firstProp.Value.Value <JObject>();

            if (jo == null)
            {
                return(null);
            }

            JToken         shape;
            JToken         indexedShape;
            IGeoShapeQuery query = null;

            if (jo.TryGetValue("shape", out shape))
            {
                query = ParseShapeQuery(shape, serializer);
            }
            else if (jo.TryGetValue("indexed_shape", out indexedShape))
            {
                query = ParseIndexedShapeQuery(indexedShape);
            }

            if (query == null)
            {
                return(null);
            }
            var boost          = jo["boost"]?.Value <double>();
            var name           = jo["_name"]?.Value <string>();
            var relation       = jo["relation"]?.Value <string>().ToEnum <GeoShapeRelation>();
            var ignoreUnmapped = jo["ignore_unmapped"]?.Value <bool>();

            query.Boost          = boost;
            query.Name           = name;
            query.Field          = field;
            query.Relation       = relation;
            query.IgnoreUnmapped = ignoreUnmapped;
            return(query);
        }
        public virtual void Visit(IGeoShapeQuery query)
        {
            // ReSharper disable UnusedVariable
            switch (query.Shape)
            {
            case null when query.IndexedShape != null:
                Write("geo_indexed_shape");
                break;

            case ICircleGeoShape circleGeoShape:
                Write("geo_shape_circle");
                break;

            case IEnvelopeGeoShape envelopeGeoShape:
                Write("geo_shape_envelope");
                break;

            case IGeometryCollection geometryCollection:
                Write("geo_shape_geometrycollection");
                break;

            case ILineStringGeoShape lineStringGeoShape:
                Write("geo_shape_linestring");
                break;

            case IMultiLineStringGeoShape multiLineStringGeoShape:
                Write("geo_shape_multi_linestring");
                break;

            case IMultiPointGeoShape multiPointGeoShape:
                Write("geo_shape_multi_point");
                break;

            case IMultiPolygonGeoShape multiPolygonGeoShape:
                Write("geo_shape_multi_polygon");
                break;

            case IPointGeoShape pointGeoShape:
                Write("geo_shape_point");
                break;

            case IPolygonGeoShape polygonGeoShape:
                Write("geo_shape_polygon");
                break;

            // ReSharper restore UnusedVariable
            default:
                Write("geo_shape", query.Field);
                break;
            }
        }
예제 #5
0
        internal static bool IsConditionless(IGeoShapeQuery q)
        {
            if (q.Field.IsConditionless())
            {
                return(true);
            }

            switch (q.Shape)
            {
            case ICircleGeoShape circleGeoShape:
                return(circleGeoShape.Coordinates == null || string.IsNullOrEmpty(circleGeoShape.Radius));

            case IEnvelopeGeoShape envelopeGeoShape:
                return(envelopeGeoShape.Coordinates == null);

            case IGeometryCollection geometryCollection:
                return(geometryCollection.Geometries == null);

            case ILineStringGeoShape lineStringGeoShape:
                return(lineStringGeoShape.Coordinates == null);

            case IMultiLineStringGeoShape multiLineStringGeoShape:
                return(multiLineStringGeoShape.Coordinates == null);

            case IMultiPointGeoShape multiPointGeoShape:
                return(multiPointGeoShape.Coordinates == null);

            case IMultiPolygonGeoShape multiPolygonGeoShape:
                return(multiPolygonGeoShape.Coordinates == null);

            case IPointGeoShape pointGeoShape:
                return(pointGeoShape.Coordinates == null);

            case IPolygonGeoShape polygonGeoShape:
                return(polygonGeoShape.Coordinates == null);

            case null:
                return(q.IndexedShape.IsConditionless());

            default:
                return(true);
            }
        }
 public virtual void Visit(IGeoShapeQuery query)
 {
     Write("geo_shape", query.Field);
 }
예제 #7
0
 public virtual void Visit(IGeoShapeQuery query)
 {
 }
예제 #8
0
 public virtual void Visit(IGeoShapeQuery query)
 {
     Write("geo_shape", query.Field);
 }
예제 #9
0
 public virtual void Visit(IGeoShapeQuery customFiltersScore)
 {
 }
 public virtual void Visit(IGeoShapeQuery query)
 {
     WriteShape(query.Shape, query.IndexedShape, query.Field, "geo_shape");
 }
예제 #11
0
		public virtual void Visit(IGeoShapeQuery query) { }
예제 #12
0
		public virtual void Visit(IGeoShapeQuery customFiltersScore)
		{
		}
예제 #13
0
 internal static bool IsConditionless(IGeoShapeQuery query) =>
 query.Field == null ||
 string.IsNullOrEmpty(query.Name) && query.Field.Type == null ||
 query.Shape == null;
예제 #14
0
        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 <JObject>();

            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 <string>();
                    if (typeName == "circle")
                    {
                        IGeoShapeCircleQuery q = new GeoShapeCircleQueryDescriptor <object>();
                        q.Shape             = new CircleGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <double> >(shape);
                        var radius = shape["radius"];
                        if (radius != null)
                        {
                            q.Shape.Radius = radius.Value <string>();
                        }
                        query = q;
                    }
                    else if (typeName == "envelope")
                    {
                        IGeoShapeEnvelopeQuery q = new GeoShapeEnvelopeQueryDescriptor <object>();
                        q.Shape             = new EnvelopeGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <IEnumerable <double> > >(shape);
                        query = q;
                    }
                    else if (typeName == "linestring")
                    {
                        IGeoShapeLineStringQuery q = new GeoShapeLineStringQueryDescriptor <object>();
                        q.Shape             = new LineStringGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <IEnumerable <double> > >(shape);
                        query = q;
                    }
                    else if (typeName == "multilinestring")
                    {
                        IGeoShapeMultiLineStringQuery q = new GeoShapeMultiLineStringQueryDescriptor <object>();
                        q.Shape             = new MultiLineStringGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <IEnumerable <IEnumerable <double> > > >(shape);
                        query = q;
                    }
                    else if (typeName == "point")
                    {
                        IGeoShapePointQuery q = new GeoShapePointQueryDescriptor <object>();
                        q.Shape             = new PointGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <double> >(shape);
                        query = q;
                    }
                    else if (typeName == "multipoint")
                    {
                        IGeoShapeMultiPointQuery q = new GeoShapeMultiPointQueryDescriptor <object>();
                        q.Shape             = new MultiPointGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <IEnumerable <double> > >(shape);
                        query = q;
                    }
                    else if (typeName == "polygon")
                    {
                        IGeoShapePolygonQuery q = new GeoShapePolygonQueryDescriptor <object>();
                        q.Shape             = new PolygonGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <IEnumerable <IEnumerable <double> > > >(shape);
                        query = q;
                    }
                    else if (typeName == "multipolygon")
                    {
                        IGeoShapeMultiPolygonQuery q = new GeoShapeMultiPolygonQueryDescriptor <object>();
                        q.Shape             = new MultiPolygonGeoShape();
                        q.Shape.Coordinates = GetCoordinates <IEnumerable <IEnumerable <IEnumerable <IEnumerable <double> > > > >(shape);
                        query = q;
                    }
                }
            }
            if (query == null)
            {
                return(null);
            }
            query.Field = field;
            return(query);
        }