/// <summary> /// Create a geohash_cell filter. /// </summary> /// <param name="field">The geo_point field to search against.</param> /// <param name="geoHash">A coordinate point object defining the geo hash.</param> /// <param name="distancePrecision">The allowed distance from the specified geo hash.</param> /// <param name="allowNeighbors">Allow the neighbors of the geo hash to be considered.</param> public GeoHashCellFilter(string field, CoordinatePoint geoHash, DistanceValue distancePrecision, bool allowNeighbors) : this(field, geoHash, allowNeighbors) { if (distancePrecision == null) throw new ArgumentNullException("distancePrecision", "GeoHashCellFilter requires a distance precision for this constructor."); DistancePrecision = distancePrecision; }
/// <summary> /// Create a geo_distance filter that searches from a central coordinate point. /// </summary> /// <param name="field">The document geo_point field.</param> /// <param name="distance">The length of the radius.</param> /// <param name="centerPoint">The central latitude and longitude of the search.</param> public GeoDistanceFilter(string field, DistanceValue distance, CoordinatePoint centerPoint) { if (string.IsNullOrWhiteSpace(field)) throw new ArgumentNullException("field", "GeoDistanceFilter requires a field."); if (distance == null) throw new ArgumentNullException("distance", "GeoDistanceFilter requires a distance."); if(centerPoint == null) throw new ArgumentNullException("centerPoint", "GeoDistanceFilter requires a central coordinate point."); Field = field; Distance = distance; CenterPoint = centerPoint; DistanceComputeMethod = GeoDistanceSerializer._DISTANCE_TYPE_DEFAULT; OptimizeBoundingBox = GeoDistanceSerializer._OPTIMIZE_BBOX_DEFAULT; Cache = GeoDistanceSerializer._CACHE_DEFAULT; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader); if (fieldDict.ContainsKey(FilterTypeEnum.GeoDistance.ToString())) fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString()); DistanceValue distance = new DistanceValue(fieldDict.GetString(_DISTANCE)); KeyValuePair<string, object> fieldKvp = fieldDict.First(x => !_KnownFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase)); if (string.IsNullOrWhiteSpace(fieldKvp.Key)) throw new RequiredPropertyMissingException("GeoPointProperty"); CoordinatePoint point = CoordinatePointSerializer.DeserializeCoordinatePoint(fieldKvp.Value.ToString()); GeoDistanceFilter filter = new GeoDistanceFilter(fieldKvp.Key, distance, point); filter.DistanceComputeMethod = DistanceComputeTypeEnum.Find(fieldDict.GetString(_DISTANCE_TYPE, _DISTANCE_TYPE_DEFAULT.ToString())); filter.OptimizeBoundingBox = BoundingBoxOptimizeEnum.Find(fieldDict.GetString(_OPTIMIZE_BBOX, _OPTIMIZE_BBOX_DEFAULT.ToString())); FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict); return filter; }
/// <summary> /// /// </summary> /// <param name="name"></param> public GeoPointProperty(string name) : base(name, PropertyTypeEnum.GeoPoint) { IndexLatLon = _INDEX_LAT_LON_DEFAULT; IndexGeoHash = _INDEX_GEO_HASH_DEFAULT; IndexGeoHashPrefix = _INDEX_GEO_HASH_PREFIX_DEFAULT; GeoHashPrecision = _GEO_HASH_PRECISION_DEFAULT; Validate = _VALIDATE_DEFAULT; ValidateLatitude = _VALIDATE_LAT_DEFAULT; ValidateLongitude = _VALIDATE_LON_DEFAULT; Normalize = _NORMALIZE_DEFAULT; NormalizeLatitude = _NORMALIZE_LAT_DEFAULT; NormalizeLongitude = _NORMALIZE_LON_DEFAULT; CompressionPrecision = _COMPRESSION_PRECISION_DEFAULT; }