We now support $minDistance for NearQuery and Criteria. Please keep in mind that minDistance is only available for MongoDB 2.6 and better and can only be combined with $near or $nearSphere operator depending on the defined index type. Usage of $minDistance with NearQuery is only possible when a 2dsphere index is present. We also make sure $minDistance operator gets correctly nested when using GeoJSON types.
It is now possible to use a Range<Distance> parameter within the repository queries. This allows to define near queries like:
findByLocationNear(Point point, Range<Distance> distances);
The lower bound of the range is treated as the minimum distance while the upper one defines the maximum distance from the given point. In case a Distance parameter is provided it will serve as maxDistance.
Original pull request: #277.
pull/280/head
Christoph Strobl11 years agocommitted byOliver Gierke
@ -104,6 +104,15 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
@@ -104,6 +104,15 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
@ -252,4 +261,5 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
@@ -252,4 +261,5 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
@ -51,9 +52,13 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@@ -51,9 +52,13 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@ -62,13 +67,14 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@@ -62,13 +67,14 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@ -115,9 +121,21 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@@ -115,9 +121,21 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@ -147,13 +165,45 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@@ -147,13 +165,45 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
@ -53,6 +53,16 @@ public class MongoParametersParameterAccessor extends ParametersParameterAccesso
@@ -53,6 +53,16 @@ public class MongoParametersParameterAccessor extends ParametersParameterAccesso
@ -55,6 +62,30 @@ public class GeoSpatial2DSphereTests extends AbstractGeoSpatialTests {
@@ -55,6 +62,30 @@ public class GeoSpatial2DSphereTests extends AbstractGeoSpatialTests {
@ -64,5 +95,4 @@ public class GeoSpatial2DSphereTests extends AbstractGeoSpatialTests {
@@ -64,5 +95,4 @@ public class GeoSpatial2DSphereTests extends AbstractGeoSpatialTests {
@ -70,6 +70,16 @@ public class GeoSpatial2DTests extends AbstractGeoSpatialTests {
@@ -70,6 +70,16 @@ public class GeoSpatial2DTests extends AbstractGeoSpatialTests {
@ -1165,4 +1165,19 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@@ -1165,4 +1165,19 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@ -96,12 +96,33 @@ public class MongoParametersParameterAccessorUnitTests {
@@ -96,12 +96,33 @@ public class MongoParametersParameterAccessorUnitTests {
@ -210,6 +210,14 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
@@ -210,6 +210,14 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
@ -283,6 +291,8 @@ Distance distance = new Distance(200, Metrics.KILOMETERS);
@@ -283,6 +291,8 @@ Distance distance = new Distance(200, Metrics.KILOMETERS);
As you can see using a `Distance` equipped with a `Metric` causes `$nearSphere` clause to be added instead of a plain `$near`. Beyond that the actual distance gets calculated according to the `Metrics` used.
NOTE: Using `@GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)` on the target property forces usage of `$nearSphere` operator.
==== Geo-near queries
[source,java]
@ -296,6 +306,11 @@ public interface PersonRepository extends MongoRepository<Person, String>
@@ -296,6 +306,11 @@ public interface PersonRepository extends MongoRepository<Person, String>
@ -1013,6 +1013,7 @@ There are also methods on the Criteria class for geospatial queries. Here is a l
@@ -1013,6 +1013,7 @@ There are also methods on the Criteria class for geospatial queries. Here is a l
* `Criteria` *withinSphere* `(Circle circle)` Creates a geospatial criterion using `$geoWithin $center` operators.
* `Criteria` *near* `(Point point)` Creates a geospatial criterion using a `$near `operation
* `Criteria` *nearSphere* `(Point point)` Creates a geospatial criterion using `$nearSphere$center` operations. This is only available for MongoDB 1.7 and higher.
* `Criteria` *minDistance* `(double minDistance)` Creates a geospatial criterion using the `$minDistance` operation, for use with $near.
* `Criteria` *maxDistance* `(double maxDistance)` Creates a geospatial criterion using the `$maxDistance` operation, for use with $near.
The `Query` class has some additional methods used to provide options for the query.