Example usage for org.springframework.data.mongodb.core.query NearQuery near

List of usage examples for org.springframework.data.mongodb.core.query NearQuery near

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query NearQuery near.

Prototype

public static NearQuery near(Point point) 

Source Link

Document

Creates a new NearQuery starting at the given Point .

Usage

From source file:org.openinfinity.tagcloud.domain.repository.TargetRepositoryMongoDBImpl.java

@Override
public List<Target> loadByCoordinates(double longitude, double latitude, double radius) {
    Point location = new Point(longitude, latitude);
    NearQuery query = NearQuery.near(location).maxDistance(new Distance(radius / 1000, Metrics.KILOMETERS));
    GeoResults<Target> targets = mongoTemplate.geoNear(query, Target.class);
    return getContentFromGeoResults(targets);
}

From source file:org.openinfinity.tagcloud.domain.repository.TargetRepositoryMongoDBImpl.java

@Override
public List<Target> loadByCoordinates(CoordinateBounds b, double radius) {
    double centerLng = (b.getnELng() + b.getsWLng()) / 2;
    double centerLat = (b.getnELat() + b.getsWLat()) / 2;
    Point location = new Point(centerLng, centerLat);

    NearQuery query = NearQuery.near(location).maxDistance(new Distance(radius / 1000, Metrics.KILOMETERS));
    GeoResults<Target> results = mongoTemplate.geoNear(query, Target.class);

    removeResultsOutsideBounds(b, results);
    return getContentFromGeoResults(results);
}

From source file:com.ninjas.movietime.repository.TheaterRepository.java

public GeoPage<Theater> listByGeoLocation(Point point, PageRequest pageRequest) {
    Preconditions.checkNotNull(point);//from  ww  w .  ja va 2 s .c o m
    Preconditions.checkNotNull(pageRequest);

    final NearQuery nearQuery = NearQuery.near(point).spherical(true).maxDistance(1, Metrics.KILOMETERS)
            .with(pageRequest);

    //final int size = getMongoTemplate().geoNear(nearQuery, Theater.class).getContent().size();

    final GeoResults<Theater> geoResults = getMongoTemplate().geoNear(nearQuery, Theater.class);

    final GeoPage<Theater> geoPage = new GeoPage<>(geoResults, pageRequest, 0);

    return geoPage;
}

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 ava 2 s  .co  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./* w  ww .ja  v  a  2  s.  c  o m*/
 */
@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)));
}