Is there not a easy method to get paginated end point for geocode nearby operation with spring jpa repository method
If i have a distributorType as not null, my code below takes too much time to run even with proper indexes
private GeoPage<Property> searchNearBy(String lat, String lng, double radius, Integer pageNumber, Integer pageSize, String distributorType) {
Point centerPoint = new Point(Double.parseDouble(lng), Double.parseDouble(lat));
Distance maxDistance = new Distance(radius, Metrics.KILOMETERS);
PageRequest page = PageRequest.of(pageNumber, pageSize);
if(distributorType == null || distributorType.isEmpty()) {
return repository.findByGeoCodeNear(centerPoint, maxDistance, page);
} else {
GeoResults<Property> result = mongoOperations.query(Property.class)
.as(Property.class)
.near(NearQuery.near(centerPoint)
.maxDistance(maxDistance)
.query(new Query(Criteria.where("distributorType").is(distributorType)))
.with(page))
.all();
long count = mongoOperations.count(new Query(Criteria.where("distributorType").is(distributorType).and("location").near(centerPoint).maxDistance(maxDistance.getValue())), Property.class);
return new GeoPage<>(result, page, count);
}
}