Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2119 Implements GeoRadiusParam.withHash() #2137

Merged
merged 5 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ public List<GeoRadiusResponse> build(Object data) {

resp.setCoordinate(new GeoCoordinate(DOUBLE.build(coord.get(0)),
DOUBLE.build(coord.get(1))));
} else if (info instanceof Long) {
// score
resp.setRawScore(LONG.build(info));
} else {
// distance
resp.setDistance(DOUBLE.build(info));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/redis/clients/jedis/GeoRadiusResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class GeoRadiusResponse {
private byte[] member;
private double distance;
private GeoCoordinate coordinate;
private long rawScore;

public GeoRadiusResponse(byte[] member) {
this.member = member;
Expand Down Expand Up @@ -34,4 +35,12 @@ public double getDistance() {
public GeoCoordinate getCoordinate() {
return coordinate;
}

public long getRawScore() {
return rawScore;
}

public void setRawScore(long rawScore) {
this.rawScore = rawScore;
}
}
12 changes: 9 additions & 3 deletions src/main/java/redis/clients/jedis/params/GeoRadiusParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
public class GeoRadiusParam extends Params {
private static final String WITHCOORD = "withcoord";
private static final String WITHDIST = "withdist";

// Do not add WITHHASH since we can't classify result of WITHHASH and WITHDIST,
// and WITHHASH is for debugging purposes
private static final String WITHHASH = "withhash";

private static final String ASC = "asc";
private static final String DESC = "desc";
Expand All @@ -33,6 +31,11 @@ public GeoRadiusParam withDist() {
return this;
}

public GeoRadiusParam withHash() {
addParam(WITHHASH);
return this;
}

public GeoRadiusParam sortAscending() {
addParam(ASC);
return this;
Expand Down Expand Up @@ -62,6 +65,9 @@ public byte[][] getByteParams(byte[]... args) {
if (contains(WITHDIST)) {
byteParams.add(SafeEncoder.encode(WITHDIST));
}
if (contains(WITHHASH)) {
byteParams.add(SafeEncoder.encode(WITHHASH));
}

if (contains(COUNT)) {
byteParams.add(SafeEncoder.encode(COUNT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,20 @@ public void georadius() {

// sort, count 1, withdist, withcoord
members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
.sortAscending().count(1).withCoord().withDist());
.sortAscending().count(1).withCoord().withDist().withHash());
assertEquals(1, members.size());
GeoRadiusResponse response = members.get(0);
assertTrue(equalsWithinEpsilon(56.4413, response.getDistance()));
assertTrue(equalsWithinEpsilon(15.087269, response.getCoordinate().getLongitude()));
assertTrue(equalsWithinEpsilon(37.502669, response.getCoordinate().getLatitude()));
assertEquals(3479447370796909L, response.getRawScore());

// sort, count 1, with hash
members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
.sortAscending().count(1).withHash());
assertEquals(1, members.size());
response = members.get(0);
assertEquals(3479447370796909L, response.getRawScore());
}

@Test
Expand Down