Add Criteria infix functions for maxDistance and minDistance.
Closes: #3761
This commit is contained in:
committed by
Mark Paluch
parent
7c6e951c7c
commit
302c8031f9
@@ -364,6 +364,28 @@ infix fun KProperty<GeoJson<*>>.maxDistance(d: Double): Criteria =
|
||||
infix fun KProperty<GeoJson<*>>.minDistance(d: Double): Criteria =
|
||||
Criteria(asString(this)).minDistance(d)
|
||||
|
||||
/**
|
||||
* Creates a geo-spatial criterion using a $maxDistance operation, for use with $near
|
||||
*
|
||||
* See [MongoDB Query operator:
|
||||
* $maxDistance](https://docs.mongodb.com/manual/reference/operator/query/maxDistance/)
|
||||
* @author Sangyong Choi
|
||||
* @since 3.2
|
||||
* @see Criteria.maxDistance
|
||||
*/
|
||||
infix fun Criteria.maxDistance(d: Double): Criteria =
|
||||
this.maxDistance(d)
|
||||
|
||||
/**
|
||||
* Creates a geospatial criterion using a $minDistance operation, for use with $near or
|
||||
* $nearSphere.
|
||||
* @author Sangyong Choi
|
||||
* @since 3.2
|
||||
* @see Criteria.minDistance
|
||||
*/
|
||||
infix fun Criteria.minDistance(d: Double): Criteria =
|
||||
this.minDistance(d)
|
||||
|
||||
/**
|
||||
* Creates a criterion using the $elemMatch operator
|
||||
*
|
||||
|
||||
@@ -317,6 +317,54 @@ class TypedCriteriaExtensionsTests {
|
||||
assertThat(typed).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `maxDistance() should equal expected criteria with nearSphere`() {
|
||||
val point = Point(0.0, 0.0)
|
||||
|
||||
val typed = Building::location nearSphere point maxDistance 3.0
|
||||
val expected = Criteria("location")
|
||||
.nearSphere(point)
|
||||
.maxDistance(3.0)
|
||||
|
||||
assertThat(typed).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `minDistance() should equal expected criteria with nearSphere`() {
|
||||
val point = Point(0.0, 0.0)
|
||||
|
||||
val typed = Building::location nearSphere point minDistance 3.0
|
||||
val expected = Criteria("location")
|
||||
.nearSphere(point)
|
||||
.minDistance(3.0)
|
||||
|
||||
assertThat(typed).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `maxDistance() should equal expected criteria with near`() {
|
||||
val point = Point(0.0, 0.0)
|
||||
|
||||
val typed = Building::location near point maxDistance 3.0
|
||||
val expected = Criteria("location")
|
||||
.near(point)
|
||||
.maxDistance(3.0)
|
||||
|
||||
assertThat(typed).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `minDistance() should equal expected criteria with near`() {
|
||||
val point = Point(0.0, 0.0)
|
||||
|
||||
val typed = Building::location near point minDistance 3.0
|
||||
val expected = Criteria("location")
|
||||
.near(point)
|
||||
.minDistance(3.0)
|
||||
|
||||
assertThat(typed).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `elemMatch() should equal expected criteria`() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user