private void cmdGeoNear_Click(object sender, EventArgs e) { BsonDocument mGeoNearAs = null; bool IsHaystack = chkHaystack.Checked; try { if (IsHaystack) { var geoSearchOption = new GeoHaystackSearchArgs() { MaxDistance = double.Parse(NumMaxDistance.Text), Limit = (int)NumResultCount.Value, Near = point }; // GeoHaystackSearch mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoHaystackSearchAs <BsonDocument>(geoSearchOption).Response; } else { var geoOption = new GeoNearArgs() { DistanceMultiplier = double.Parse(NumDistanceMultiplier.Text), MaxDistance = double.Parse(NumMaxDistance.Text), Spherical = chkSpherical.Checked, Limit = (int)NumResultCount.Value }; if (radGeoJSON.Checked) { geoOption.Near = new GeoJsonPoint <GeoJson2DCoordinates>(new GeoJson2DCoordinates(point.X, point.Y)); } else { geoOption.Near = point; } //GeoNearAs mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoNearAs <BsonDocument>(geoOption).Response; } } catch (Exception ex) { Utility.ExceptionDeal(ex); return; } UiHelper.FillDataToTreeView("Result", trvGeoResult, mGeoNearAs); trvGeoResult.DatatreeView.Nodes[0].Expand(); }
private void cmdGeoNear_Click(object sender, EventArgs e) { BsonDocument mGeoNearAs = null; bool IsHaystack = chkHaystack.Checked; try { if (IsHaystack) { var geoSearchOption = new GeoHaystackSearchArgs(); geoSearchOption.MaxDistance = double.Parse(NumMaxDistance.Text); geoSearchOption.Limit = (int)NumResultCount.Value; geoSearchOption.Near = new XYPoint(double.Parse(NumGeoX.Text), double.Parse(NumGeoY.Text)); //geoSearch mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoHaystackSearchAs <BsonDocument>(geoSearchOption).Response; } else { var geoOption = new GeoNearArgs(); geoOption.DistanceMultiplier = double.Parse(NumDistanceMultiplier.Text); geoOption.MaxDistance = double.Parse(NumMaxDistance.Text); geoOption.Spherical = chkSpherical.Checked; geoOption.Limit = (int)NumResultCount.Value; geoOption.Near = new XYPoint(double.Parse(NumGeoX.Text), double.Parse(NumGeoY.Text)); //geoNear mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoNearAs <BsonDocument>(geoOption).Response; } } catch (Exception ex) { Utility.ExceptionDeal(ex); return; } UiHelper.FillDataToTreeView("Result", trvGeoResult, mGeoNearAs); trvGeoResult.DatatreeView.Nodes[0].Expand(); }
public void TestGeoHaystackSearch_Typed() { using (_database.RequestStart()) { var instance = _server.RequestConnection.ServerInstance; if (instance.InstanceType != MongoServerInstanceType.ShardRouter) { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new Place { Location = new[] { 34.2, 33.3 }, Type = "restaurant" }); _collection.Insert(new Place { Location = new[] { 34.2, 37.3 }, Type = "restaurant" }); _collection.Insert(new Place { Location = new[] { 59.1, 87.2 }, Type = "office" }); _collection.EnsureIndex(IndexKeys<Place>.GeoSpatialHaystack(x => x.Location, x => x.Type), IndexOptions.SetBucketSize(1)); var args = new GeoHaystackSearchArgs { Near = GeoNearPoint.From(33, 33), Limit = 30, MaxDistance = 6 } .SetAdditionalField<Place, string>(x => x.Type, "restaurant"); var result = _collection.GeoHaystackSearchAs<Place>(args); Assert.IsTrue(result.Ok); Assert.IsTrue(result.Stats.Duration >= TimeSpan.Zero); Assert.AreEqual(2, result.Stats.BTreeMatches); Assert.AreEqual(2, result.Stats.NumberOfHits); Assert.AreEqual(34.2, result.Hits[0].Document.Location[0]); Assert.AreEqual(33.3, result.Hits[0].Document.Location[1]); Assert.AreEqual("restaurant", result.Hits[0].Document.Type); Assert.AreEqual(34.2, result.Hits[1].Document.Location[0]); Assert.AreEqual(37.3, result.Hits[1].Document.Location[1]); Assert.AreEqual("restaurant", result.Hits[1].Document.Type); } } }
public void TestGeoHaystackSearchWithMaxTime() { if (_primary.Supports(FeatureId.MaxTime)) { if (_primary.InstanceType != MongoServerInstanceType.ShardRouter) { using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary)) { if (failpoint.IsSupported()) { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new Place { Location = new[] { 34.2, 33.3 }, Type = "restaurant" }); _collection.Insert(new Place { Location = new[] { 34.2, 37.3 }, Type = "restaurant" }); _collection.Insert(new Place { Location = new[] { 59.1, 87.2 }, Type = "office" }); _collection.EnsureIndex(IndexKeys.GeoSpatialHaystack("Location", "Type"), IndexOptions.SetBucketSize(1)); failpoint.SetAlwaysOn(); var args = new GeoHaystackSearchArgs { Near = GeoNearPoint.From(33, 33), AdditionalFieldName = "Type", AdditionalFieldValue = "restaurant", Limit = 30, MaxDistance = 6, MaxTime = TimeSpan.FromMilliseconds(1) }; Assert.Throws<ExecutionTimeoutException>(() => _collection.GeoHaystackSearchAs<Place>(args)); } } } } }
public void TestGeoHaystackSearch() { if (_primary.InstanceType != MongoServerInstanceType.ShardRouter) { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new Place { Location = new[] { 34.2, 33.3 }, Type = "restaurant" }); _collection.Insert(new Place { Location = new[] { 34.2, 37.3 }, Type = "restaurant" }); _collection.Insert(new Place { Location = new[] { 59.1, 87.2 }, Type = "office" }); _collection.CreateIndex(IndexKeys.GeoSpatialHaystack("Location", "Type"), IndexOptions.SetBucketSize(1)); var args = new GeoHaystackSearchArgs { Near = new XYPoint(33, 33), AdditionalFieldName = "Type", AdditionalFieldValue = "restaurant", Limit = 30, MaxDistance = 6 }; var result = _collection.GeoHaystackSearchAs<Place>(args); Assert.IsTrue(result.Ok); Assert.IsTrue(result.Stats.Duration >= TimeSpan.Zero); Assert.AreEqual(2, result.Stats.BTreeMatches); Assert.AreEqual(2, result.Stats.NumberOfHits); Assert.AreEqual(34.2, result.Hits[0].Document.Location[0]); Assert.AreEqual(33.3, result.Hits[0].Document.Location[1]); Assert.AreEqual("restaurant", result.Hits[0].Document.Type); Assert.AreEqual(34.2, result.Hits[1].Document.Location[0]); Assert.AreEqual(37.3, result.Hits[1].Document.Location[1]); Assert.AreEqual("restaurant", result.Hits[1].Document.Type); } }
private void cmdGeoNear_Click(object sender, EventArgs e) { BsonDocument mGeoNearAs = null; bool IsHaystack = chkHaystack.Checked; try { if (IsHaystack) { var geoSearchOption = new GeoHaystackSearchArgs(); geoSearchOption.MaxDistance = double.Parse(NumMaxDistance.Text); geoSearchOption.Limit = (int)NumResultCount.Value; geoSearchOption.Near = point; // GeoHaystackSearch mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoHaystackSearchAs<BsonDocument>(geoSearchOption).Response; } else { var geoOption = new GeoNearArgs(); geoOption.DistanceMultiplier = double.Parse(NumDistanceMultiplier.Text); geoOption.MaxDistance = double.Parse(NumMaxDistance.Text); geoOption.Spherical = chkSpherical.Checked; geoOption.Limit = (int)NumResultCount.Value; if (radGeoJSON.Checked) { geoOption.Near = new GeoJsonPoint<GeoJson2DCoordinates>(new GeoJson2DCoordinates(point.X, point.Y)); } else { geoOption.Near = point; } //GeoNearAs mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoNearAs<BsonDocument>(geoOption).Response; } } catch (Exception ex) { Utility.ExceptionDeal(ex); return; } UiHelper.FillDataToTreeView("Result", trvGeoResult, mGeoNearAs); trvGeoResult.DatatreeView.Nodes[0].Expand(); }