Skip to content

Commit 4bb1a1a

Browse files
committed
Use simple version of HSET (#3587)
for easier readability
1 parent 25ffc37 commit 4bb1a1a

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package redis.clients.jedis.examples;
22

3+
import java.util.Collections;
4+
import org.junit.Assert;
5+
36
import org.locationtech.jts.geom.Coordinate;
47
import org.locationtech.jts.geom.Geometry;
58
import org.locationtech.jts.geom.GeometryFactory;
@@ -11,13 +14,10 @@
1114
import redis.clients.jedis.JedisPooled;
1215
import redis.clients.jedis.UnifiedJedis;
1316
import redis.clients.jedis.search.FTSearchParams;
17+
import redis.clients.jedis.search.RediSearchUtil;
1418
import redis.clients.jedis.search.SearchResult;
1519
import redis.clients.jedis.search.schemafields.GeoShapeField;
1620

17-
import static java.util.Collections.singletonMap;
18-
import static org.junit.Assert.assertEquals;
19-
import static redis.clients.jedis.search.RediSearchUtil.toStringMap;
20-
2121
/**
2222
* As of RediSearch 2.8.4, advanced GEO querying with GEOSHAPE fields is supported.
2323
*
@@ -64,15 +64,17 @@ public static void main(String[] args) {
6464
new Coordinate(34.9100, 29.7001), new Coordinate(34.9001, 29.7001)}
6565
);
6666

67-
client.hset("small", toStringMap(singletonMap("geometry", small))); // setting data
67+
// client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geometry", small))); // setting data
68+
client.hset("small", "geometry", small.toString()); // simplified setting data
6869

6970
final Polygon large = factory.createPolygon(
7071
new Coordinate[]{new Coordinate(34.9001, 29.7001),
7172
new Coordinate(34.9001, 29.7200), new Coordinate(34.9200, 29.7200),
7273
new Coordinate(34.9200, 29.7001), new Coordinate(34.9001, 29.7001)}
7374
);
7475

75-
client.hset("large", toStringMap(singletonMap("geometry", large))); // setting data
76+
// client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geometry", large))); // setting data
77+
client.hset("large", "geometry", large.toString()); // simplified setting data
7678

7779
// searching
7880
final Polygon within = factory.createPolygon(
@@ -88,14 +90,14 @@ public static void main(String[] args) {
8890
.addParam("poly", within)
8991
.dialect(3) // DIALECT '3' is required for this query
9092
);
91-
assertEquals(1, res.getTotalResults());
92-
assertEquals(1, res.getDocuments().size());
93+
Assert.assertEquals(1, res.getTotalResults());
94+
Assert.assertEquals(1, res.getDocuments().size());
9395

9496
// We can parse geometry objects with WKTReader
9597
try {
9698
final WKTReader reader = new WKTReader();
9799
Geometry object = reader.read(res.getDocuments().get(0).getString("geometry"));
98-
assertEquals(small, object);
100+
Assert.assertEquals(small, object);
99101
} catch (ParseException ex) {
100102
ex.printStackTrace(System.err);
101103
}

src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ public void geoShapeFilterSpherical() throws ParseException {
351351
final Polygon small = factory.createPolygon(new Coordinate[]{new Coordinate(34.9001, 29.7001),
352352
new Coordinate(34.9001, 29.7100), new Coordinate(34.9100, 29.7100),
353353
new Coordinate(34.9100, 29.7001), new Coordinate(34.9001, 29.7001)});
354-
client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geom", small)));
354+
client.hset("small", "geom", small.toString());
355355

356356
final Polygon large = factory.createPolygon(new Coordinate[]{new Coordinate(34.9001, 29.7001),
357357
new Coordinate(34.9001, 29.7200), new Coordinate(34.9200, 29.7200),
358358
new Coordinate(34.9200, 29.7001), new Coordinate(34.9001, 29.7001)});
359-
client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geom", large)));
359+
client.hset("large", "geom", large.toString());
360360

361361
// within condition
362362
final Polygon within = factory.createPolygon(new Coordinate[]{new Coordinate(34.9000, 29.7000),
@@ -381,7 +381,7 @@ public void geoShapeFilterSpherical() throws ParseException {
381381

382382
// point type
383383
final Point point = factory.createPoint(new Coordinate(34.9010, 29.7010));
384-
client.hset("point", RediSearchUtil.toStringMap(Collections.singletonMap("geom", point)));
384+
client.hset("point", "geom", point.toString());
385385

386386
res = client.ftSearch(index, "@geom:[within $poly]",
387387
FTSearchParams.searchParams().addParam("poly", within).dialect(3));
@@ -399,11 +399,11 @@ public void geoShapeFilterFlat() throws ParseException {
399399
// polygon type
400400
final Polygon small = factory.createPolygon(new Coordinate[]{new Coordinate(1, 1),
401401
new Coordinate(1, 100), new Coordinate(100, 100), new Coordinate(100, 1), new Coordinate(1, 1)});
402-
client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geom", small)));
402+
client.hset("small", "geom", small.toString());
403403

404404
final Polygon large = factory.createPolygon(new Coordinate[]{new Coordinate(1, 1),
405405
new Coordinate(1, 200), new Coordinate(200, 200), new Coordinate(200, 1), new Coordinate(1, 1)});
406-
client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geom", large)));
406+
client.hset("large", "geom", large.toString());
407407

408408
// within condition
409409
final Polygon within = factory.createPolygon(new Coordinate[]{new Coordinate(0, 0),
@@ -426,7 +426,7 @@ public void geoShapeFilterFlat() throws ParseException {
426426

427427
// point type
428428
final Point point = factory.createPoint(new Coordinate(10, 10));
429-
client.hset("point", RediSearchUtil.toStringMap(Collections.singletonMap("geom", point)));
429+
client.hset("point", "geom", point.toString());
430430

431431
res = client.ftSearch(index, "@geom:[within $poly]",
432432
FTSearchParams.searchParams().addParam("poly", within).dialect(3));
@@ -1130,9 +1130,9 @@ public void maxPrefixExpansionSearchProfile() {
11301130
client.ftConfigSet(configParam, "2");
11311131

11321132
assertOK(client.ftCreate(index, TextField.of("t")));
1133-
client.hset("1", Collections.singletonMap("t", "foo1"));
1134-
client.hset("2", Collections.singletonMap("t", "foo2"));
1135-
client.hset("3", Collections.singletonMap("t", "foo3"));
1133+
client.hset("1", "t", "foo1");
1134+
client.hset("2", "t", "foo2");
1135+
client.hset("3", "t", "foo3");
11361136

11371137
Map.Entry<SearchResult, Map<String, Object>> reply = client.ftProfileSearch(index,
11381138
FTProfileParams.profileParams(), "foo*", FTSearchParams.searchParams().limit(0, 0));
@@ -1152,8 +1152,8 @@ public void maxPrefixExpansionSearchProfile() {
11521152
@Test
11531153
public void noContentSearchProfile() {
11541154
assertOK(client.ftCreate(index, TextField.of("t")));
1155-
client.hset("1", Collections.singletonMap("t", "foo"));
1156-
client.hset("2", Collections.singletonMap("t", "bar"));
1155+
client.hset("1", "t", "foo");
1156+
client.hset("2", "t", "bar");
11571157

11581158
Map.Entry<SearchResult, Map<String, Object>> profile = client.ftProfileSearch(index,
11591159
FTProfileParams.profileParams(), "foo -@t:baz", FTSearchParams.searchParams().noContent());
@@ -1179,8 +1179,8 @@ public void noContentSearchProfile() {
11791179
@Test
11801180
public void deepReplySearchProfile() {
11811181
assertOK(client.ftCreate(index, TextField.of("t")));
1182-
client.hset("1", Collections.singletonMap("t", "hello"));
1183-
client.hset("2", Collections.singletonMap("t", "world"));
1182+
client.hset("1", "t", "hello");
1183+
client.hset("2", "t", "world");
11841184

11851185
Map.Entry<SearchResult, Map<String, Object>> profile
11861186
= client.ftProfileSearch(index, FTProfileParams.profileParams(),
@@ -1217,10 +1217,10 @@ public void deepReplySearchProfile() {
12171217
@Test
12181218
public void limitedSearchProfile() {
12191219
assertOK(client.ftCreate(index, TextField.of("t")));
1220-
client.hset("1", Collections.singletonMap("t", "hello"));
1221-
client.hset("2", Collections.singletonMap("t", "hell"));
1222-
client.hset("3", Collections.singletonMap("t", "help"));
1223-
client.hset("4", Collections.singletonMap("t", "helowa"));
1220+
client.hset("1", "t", "hello");
1221+
client.hset("2", "t", "hell");
1222+
client.hset("3", "t", "help");
1223+
client.hset("4", "t", "helowa");
12241224

12251225
Map.Entry<SearchResult, Map<String, Object>> profile = client.ftProfileSearch(index,
12261226
FTProfileParams.profileParams().limited(), "%hell% hel*", FTSearchParams.searchParams().noContent());

0 commit comments

Comments
 (0)