List of usage examples for org.springframework.data.geo GeoResults getContent
public List<GeoResult<T>> getContent()
From source file:example.springdata.mongodb.customer.CustomerRepositoryIntegrationTest.java
/** * Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of a reference point. *//* w ww .ja v a 2 s . co m*/ @Test public void exposesGeoSpatialFunctionality() { GeospatialIndex indexDefinition = new GeospatialIndex("address.location"); indexDefinition.getIndexOptions().put("min", -180); indexDefinition.getIndexOptions().put("max", 180); operations.indexOps(Customer.class).ensureIndex(indexDefinition); Customer ollie = new Customer("Oliver", "Gierke"); ollie.setAddress(new Address(new Point(52.52548, 13.41477))); ollie = repository.save(ollie); Point referenceLocation = new Point(52.51790, 13.41239); Distance oneKilometer = new Distance(1, Metrics.KILOMETERS); GeoResults<Customer> result = repository.findByAddressLocationNear(referenceLocation, oneKilometer); assertThat(result.getContent(), hasSize(1)); Distance distanceToFirstStore = result.getContent().get(0).getDistance(); assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS)); assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001)); }
From source file:example.ComposedAnnotationIntegrationTest.java
/** * Issue a {@code geoNear} query using a 2d legacy index specified by the built-in {@link GeospatialIndex} annotation. *//*from w w w . j a va 2 s . c o m*/ @Test public void findsVenuesWithRegularAnnotations() { GeoResults<Venue> geoResults = operations .geoNear(NearQuery.near(jessesHouse.getPoint()).maxDistance(10, Metrics.MILES), Venue.class); assertThat(geoResults.getContent(), hasSize(2)); GeoResult<Venue> geoResult = geoResults.getContent().get(1); assertThat(geoResult.getContent(), is(equalTo(theWhiteResidence))); assertThat(geoResult.getDistance().getValue(), is(closeTo(7.7, 0.1))); }
From source file:example.ComposedAnnotationIntegrationTest.java
/** * Issue a {@code geoNear} query using a 2d legacy index specified by a custom, composed {@link MyGeoIndexAnnotation} * annotation.//from w ww. j a va 2 s . c om */ @Test public void findsVenuesWithComposedAnnotations() { GeoResults<ImprovedVenue> geoResults = operations.geoNear( NearQuery.near(theWhiteResidence.getPoint()).maxDistance(2, Metrics.MILES), ImprovedVenue.class); assertThat(geoResults.getContent(), hasSize(2)); GeoResult<ImprovedVenue> geoResult = geoResults.getContent().get(1); assertThat(geoResult.getContent(), is(equalTo(carWash))); assertThat(geoResult.getDistance().getValue(), is(closeTo(1.2, 0.1))); }
From source file:example.springdata.mongodb.fluent.FluentMongoApiTests.java
/** * GeoNear operations can be executed via {@code near} which needs to be given a {@link NearQuery}. By doing so the * API will from then on only provide methods suitable for executing a {@literal near} query. In this case options * like {@code first()} or {@code one()} are no longer available. Even the return type for {@code all()} switches from * {@link List} to {@link GeoResults}. <br /> * Still it is possible to map the {@code content} of a single {@link org.springframework.data.geo.GeoResult} to a * different type using {@code as(Class)}. <br /> * The samples below would read something like the following using classic {@link MongoOperations}. * * <pre>// ww w.j a v a 2s.co m * <code> * template.geoNear(alderaanWithin3Parsecs, SWCharacter.class, "star-wars", Jedi.class); * </code> * </pre> */ @Test public void geoNearQuery() { GeoResults<Jedi> results = mongoOps.query(SWCharacter.class) // SWCharacter defines collection, id and name .as(Jedi.class) // but we want to map the results to Jedi .near(alderaanWithin3Parsecs) // and find those with home planet near alderaan .all(); assertThat(results.getContent()).hasSize(2); }
From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java
@Test public void executesGeoNearQueryForResultsCorrectly() { Point point = new Point(-73.99171, 40.738868); dave.setLocation(point);//from w ww . j a va 2s .co m repository.save(dave); GeoResults<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS)); assertThat(results.getContent().isEmpty(), is(false)); }
From source file:org.springframework.data.mongodb.core.geo.GeoSpatialTests.java
@Test public void geoNear() { NearQuery geoNear = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).maxDistance(150); GeoResults<Venue> result = template.geoNear(geoNear, Venue.class); assertThat(result.getContent().size(), is(not(0))); assertThat(result.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS)); }