//Failing test from http://groups.google.com/group/ravendb/browse_thread/thread/7a93f37036297d48/ public void CanSuccessfullyDoSpatialQueryOfNearbyLocations() { // These items is in a radius of 4 miles (approx 6,5 km) var areaOneDocOne = new DummyGeoDoc(55.6880508001, 13.5717346673); var areaOneDocTwo = new DummyGeoDoc(55.6821978456, 13.6076183965); var areaOneDocThree = new DummyGeoDoc(55.673251569, 13.5946697607); // This item is 12 miles (approx 19 km) from the closest in areaOne var closeButOutsideAreaOne = new DummyGeoDoc(55.8634157297, 13.5497731987); // This item is about 3900 miles from areaOne var newYork = new DummyGeoDoc(40.7137578228, -74.0126901936); using (var store = GetDocumentStore()) using (var session = store.OpenSession()) { session.Store(areaOneDocOne); session.Store(areaOneDocTwo); session.Store(areaOneDocThree); session.Store(closeButOutsideAreaOne); session.Store(newYork); session.SaveChanges(); var indexDefinition = new IndexDefinition { Name = "FindByLatLng", Maps = { "from doc in docs select new { Coordinates = CreateSpatialField(doc.Latitude, doc.Longitude) }" } }; store.Maintenance.Send(new PutIndexesOperation(indexDefinition)); // Wait until the index is built session.Advanced.DocumentQuery <DummyGeoDoc>("FindByLatLng") .WaitForNonStaleResults() .ToArray(); const double lat = 55.6836422426, lng = 13.5871808352; // in the middle of AreaOne const double radius = 5.0; // Expected is that 5.0 will return 3 results var nearbyDocs = session.Advanced.DocumentQuery <DummyGeoDoc>("FindByLatLng") .WithinRadiusOf("Coordinates", radius, lat, lng) .WaitForNonStaleResults() .ToArray(); Assert.NotEqual(null, nearbyDocs); Assert.Equal(3, nearbyDocs.Length); //TODO //var dist = DistanceUtils.GetInstance(); //Assert.Equal(true, nearbyDocs.All(x => dist.GetDistanceMi(x.Latitude, x.Longitude, lat, lng) < radius)); session.Dispose(); } }
//Failing test from http://groups.google.com/group/ravendb/browse_thread/thread/7a93f37036297d48/ public void CanSuccessfullyDoSpatialQueryOfNearbyLocations() { // These items is in a radius of 4 miles (approx 6,5 km) var areaOneDocOne = new DummyGeoDoc(55.6880508001, 13.5717346673); var areaOneDocTwo = new DummyGeoDoc(55.6821978456, 13.6076183965); var areaOneDocThree = new DummyGeoDoc(55.673251569, 13.5946697607); // This item is 12 miles (approx 19 km) from the closests in areaOne var closeButOutsideAreaOne = new DummyGeoDoc(55.8634157297, 13.5497731987); // This item is about 3900 miles from areaOne var newYork = new DummyGeoDoc(40.7137578228, -74.0126901936); var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; documentStore.Initialize(); var session = documentStore.OpenSession(); session.Store(areaOneDocOne); session.Store(areaOneDocTwo); session.Store(areaOneDocThree); session.Store(closeButOutsideAreaOne); session.Store(newYork); session.SaveChanges(); var indexDefinition = new IndexDefinition { Map = "from doc in docs select new { _ = SpatialIndex.Generate(doc.Latitude, doc.Longitude) }" }; documentStore.DatabaseCommands.PutIndex("FindByLatLng", indexDefinition); // Wait until the index is built session.Advanced.LuceneQuery <DummyGeoDoc>("FindByLatLng") .WaitForNonStaleResults() .ToArray(); const double lat = 55.6836422426, lng = 13.5871808352; // in the middle of AreaOne const double radius = 5.0; // Expcted is that 5.0 will return 3 results var nearbyDocs = session.Advanced.LuceneQuery <DummyGeoDoc>("FindByLatLng") .WithinRadiusOf(radius, lat, lng) .WaitForNonStaleResults() .ToArray(); Assert.NotEqual(null, nearbyDocs); Assert.Equal(3, nearbyDocs.Length); var dist = DistanceUtils.GetInstance(); Assert.Equal(true, nearbyDocs.All(x => dist.GetDistanceMi(x.Latitude, x.Longitude, lat, lng) < radius)); session.Dispose(); }
//Failing test from http://groups.google.com/group/ravendb/browse_thread/thread/7a93f37036297d48/ public void CanSuccessfullyDoSpatialQueryOfNearbyLocations() { // These items is in a radius of 4 miles (approx 6,5 km) var areaOneDocOne = new DummyGeoDoc(55.6880508001, 13.5717346673); var areaOneDocTwo = new DummyGeoDoc(55.6821978456, 13.6076183965); var areaOneDocThree = new DummyGeoDoc(55.673251569, 13.5946697607); // This item is 12 miles (approx 19 km) from the closest in areaOne var closeButOutsideAreaOne = new DummyGeoDoc(55.8634157297, 13.5497731987); // This item is about 3900 miles from areaOne var newYork = new DummyGeoDoc(40.7137578228, -74.0126901936); using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true }.Initialize()) using (var session = documentStore.OpenSession()) { session.Store(areaOneDocOne); session.Store(areaOneDocTwo); session.Store(areaOneDocThree); session.Store(closeButOutsideAreaOne); session.Store(newYork); session.SaveChanges(); var indexDefinition = new IndexDefinition { Map = "from doc in docs select new { _ = SpatialIndex.Generate(doc.Latitude, doc.Longitude) }" }; documentStore.DatabaseCommands.PutIndex("FindByLatLng", indexDefinition); // Wait until the index is built session.Advanced.LuceneQuery<DummyGeoDoc>("FindByLatLng") .WaitForNonStaleResults() .ToArray(); const double lat = 55.6836422426, lng = 13.5871808352; // in the middle of AreaOne const double radius = 5.0; // Expected is that 5.0 will return 3 results var nearbyDocs = session.Advanced.LuceneQuery<DummyGeoDoc>("FindByLatLng") .WithinRadiusOf(radius, lat, lng) .WaitForNonStaleResults() .ToArray(); Assert.NotEqual(null, nearbyDocs); Assert.Equal(3, nearbyDocs.Length); //TODO //var dist = DistanceUtils.GetInstance(); //Assert.Equal(true, nearbyDocs.All(x => dist.GetDistanceMi(x.Latitude, x.Longitude, lat, lng) < radius)); session.Dispose(); } }
public void CanSuccessfullyQueryByMiles() { var myHouse = new DummyGeoDoc(44.757767, -93.355322); // The gym is about 7.32 miles (11.79 kilometers) from my house. var gym = new DummyGeoDoc(44.682861, -93.25); using (var store = GetDocumentStore()) using (var session = store.OpenSession()) { session.Store(myHouse); session.Store(gym); session.SaveChanges(); var indexDefinition = new IndexDefinition { Name = "FindByLatLng", Maps = { "from doc in docs select new { Coordinates = CreateSpatialField(doc.Latitude, doc.Longitude) }" } }; store.Maintenance.Send(new PutIndexesOperation(indexDefinition)); // Wait until the index is built session.Advanced.DocumentQuery <DummyGeoDoc>("FindByLatLng") .WaitForNonStaleResults() .ToArray(); const double radius = 8; // Find within 8 miles. // We should find both my house and the gym. var matchesWithinMiles = session.Advanced.DocumentQuery <DummyGeoDoc>("FindByLatLng") .WithinRadiusOf("Coordinates", radius, myHouse.Latitude, myHouse.Longitude, SpatialUnits.Miles) .WaitForNonStaleResults() .ToArray(); Assert.NotEqual(null, matchesWithinMiles); Assert.Equal(2, matchesWithinMiles.Length); // Find within 8 kilometers. // We should find only my house, since the gym is ~11 kilometers out. var matchesWithinKilometers = session.Advanced.DocumentQuery <DummyGeoDoc>("FindByLatLng") .WithinRadiusOf("Coordinates", radius, myHouse.Latitude, myHouse.Longitude, SpatialUnits.Kilometers) .WaitForNonStaleResults() .ToArray(); Assert.NotEqual(null, matchesWithinKilometers); Assert.Equal(1, matchesWithinKilometers.Length); } }
public void CanSuccessfullyQueryByMiles() { var myHouse = new DummyGeoDoc(44.757767, -93.355322); // The gym is about 7.32 miles (11.79 kilometers) from my house. var gym = new DummyGeoDoc(44.682861, -93.25); using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true }.Initialize()) using (var session = documentStore.OpenSession()) { session.Store(myHouse); session.Store(gym); session.SaveChanges(); var indexDefinition = new IndexDefinition { Map = "from doc in docs select new { _ = SpatialGenerate(doc.Latitude, doc.Longitude) }" }; documentStore.DatabaseCommands.PutIndex("FindByLatLng", indexDefinition); // Wait until the index is built session.Advanced.LuceneQuery <DummyGeoDoc>("FindByLatLng") .WaitForNonStaleResults() .ToArray(); const double radius = 8; // Find within 8 miles. // We should find both my house and the gym. var matchesWithinMiles = session.Advanced.LuceneQuery <DummyGeoDoc>("FindByLatLng") .WithinRadiusOf(radius, myHouse.Latitude, myHouse.Longitude, SpatialUnits.Miles) .WaitForNonStaleResults() .ToArray(); Assert.NotEqual(null, matchesWithinMiles); Assert.Equal(2, matchesWithinMiles.Length); // Find within 8 kilometers. // We should find only my house, since the gym is ~11 kilometers out. var matchesWithinKilometers = session.Advanced.LuceneQuery <DummyGeoDoc>("FindByLatLng") .WithinRadiusOf(radius, myHouse.Latitude, myHouse.Longitude, SpatialUnits.Kilometers) .WaitForNonStaleResults() .ToArray(); Assert.NotEqual(null, matchesWithinKilometers); Assert.Equal(1, matchesWithinKilometers.Length); } }
public void Test() { var myHouse = new DummyGeoDoc(44.757767, -93.355322); // The gym is about 7.32 miles (11.79 kilometers) from my house. var gym = new DummyGeoDoc(44.682861, -93.25); using (var store = GetDocumentStore()) { store.Initialize(); store.ExecuteIndex(new KmGeoIndex()); store.ExecuteIndex(new MilesGeoIndex()); using (var session = store.OpenSession()) { session.Store(myHouse); session.Store(gym); session.SaveChanges(); } WaitForIndexing(store); using (var session = store.OpenSession()) { var km = session.Query <DummyGeoDoc, KmGeoIndex>() .Spatial(x => x.Location, x => x.WithinRadius(8, myHouse.Latitude, myHouse.Longitude)) .Count(); Assert.Equal(1, km); var miles = session.Query <DummyGeoDoc, MilesGeoIndex>() .Spatial(x => x.Location, x => x.WithinRadius(8, myHouse.Latitude, myHouse.Longitude)) .Count(); Assert.Equal(2, miles); } using (var session = store.OpenSession()) { var km = session.Query <DummyGeoDoc, KmGeoIndex>() .Spatial("Location", factory => factory.WithinRadius(8, myHouse.Latitude, myHouse.Longitude)) .Count(); Assert.Equal(1, km); var miles = session.Query <DummyGeoDoc, MilesGeoIndex>() .Spatial("Location", factory => factory.WithinRadius(8, myHouse.Latitude, myHouse.Longitude)) .Count(); Assert.Equal(2, miles); } using (var session = store.OpenSession()) { var miles = session.Query <DummyGeoDoc, MilesGeoIndex>() .Spatial("Location", factory => factory.WithinRadius(8, myHouse.Latitude, myHouse.Longitude, SpatialUnits.Kilometers)) .Count(); Assert.Equal(1, miles); var km = session.Query <DummyGeoDoc, KmGeoIndex>() .Spatial("Location", factory => factory.WithinRadius(8, myHouse.Latitude, myHouse.Longitude, SpatialUnits.Miles)) .Count(); Assert.Equal(2, km); } } }