Pass Page.size() to GEORADIUS COUNT.
We now reuse the page size to initially limit Geo results within Redis. Closes #1242
This commit is contained in:
@@ -32,6 +32,7 @@ import org.springframework.data.keyvalue.core.SortAccessor;
|
||||
import org.springframework.data.keyvalue.core.SpelSortAccessor;
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||
import org.springframework.data.redis.core.convert.GeoIndexedPropertyValue;
|
||||
import org.springframework.data.redis.core.convert.RedisData;
|
||||
import org.springframework.data.redis.repository.query.RedisOperationChain;
|
||||
@@ -104,8 +105,14 @@ class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationC
|
||||
|
||||
if (criteria.getNear() != null) {
|
||||
|
||||
GeoRadiusCommandArgs limit = GeoRadiusCommandArgs.newGeoRadiusArgs();
|
||||
|
||||
if (rows > 0) {
|
||||
limit = limit.limit(rows);
|
||||
}
|
||||
|
||||
GeoResults<GeoLocation<byte[]>> x = connection.geoRadius(geoKey(keyspace + ":", criteria.getNear()),
|
||||
new Circle(criteria.getNear().getPoint(), criteria.getNear().getDistance()));
|
||||
new Circle(criteria.getNear().getPoint(), criteria.getNear().getDistance()), limit);
|
||||
for (GeoResult<GeoLocation<byte[]>> y : x) {
|
||||
allKeys.add(y.getContent().getName());
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Metrics;
|
||||
@@ -443,6 +444,28 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
assertThat(result).contains(p2).doesNotContain(p1);
|
||||
}
|
||||
|
||||
@Test // GH-1242
|
||||
void nearQueryShouldConsiderLimit() {
|
||||
|
||||
City palermo = new City();
|
||||
palermo.location = new Point(13.361389D, 38.115556D);
|
||||
|
||||
City catania = new City();
|
||||
catania.location = new Point(15.087269D, 37.502669D);
|
||||
|
||||
Person p1 = new Person("foo", "bar");
|
||||
p1.hometown = palermo;
|
||||
|
||||
Person p2 = new Person("two", "two");
|
||||
p2.hometown = catania;
|
||||
|
||||
repo.saveAll(Arrays.asList(p1, p2));
|
||||
|
||||
Slice<Person> result = repo.findByHometownLocationNear(new Point(15D, 37D), new Distance(200, Metrics.KILOMETERS),
|
||||
Pageable.ofSize(1));
|
||||
assertThat(result).containsOnly(p2);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-849
|
||||
void shouldReturnNewObjectInstanceOnImmutableSave() {
|
||||
|
||||
@@ -508,6 +531,8 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
|
||||
List<Person> findByHometownLocationNear(Point point, Distance distance);
|
||||
|
||||
Slice<Person> findByHometownLocationNear(Point point, Distance distance, Pageable pageable);
|
||||
|
||||
@Override
|
||||
<S extends Person> List<S> findAll(Example<S> example);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user