From 33507201f56512a4471dc103585c0250658aea9c Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:25:17 +0600 Subject: [PATCH] Use simple version of HSET (#3587) for easier readability --- .../GeoShapeFieldsUsageInRediSearch.java | 20 ++++++----- .../modules/search/SearchWithParamsTest.java | 34 +++++++++---------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java b/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java index db4db2cb0f..fd309def50 100644 --- a/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java +++ b/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java @@ -1,5 +1,8 @@ package redis.clients.jedis.examples; +import java.util.Collections; +import org.junit.Assert; + import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; @@ -11,13 +14,10 @@ import redis.clients.jedis.JedisPooled; import redis.clients.jedis.UnifiedJedis; import redis.clients.jedis.search.FTSearchParams; +import redis.clients.jedis.search.RediSearchUtil; import redis.clients.jedis.search.SearchResult; import redis.clients.jedis.search.schemafields.GeoShapeField; -import static java.util.Collections.singletonMap; -import static org.junit.Assert.assertEquals; -import static redis.clients.jedis.search.RediSearchUtil.toStringMap; - /** * As of RediSearch 2.8.4, advanced GEO querying with GEOSHAPE fields is supported. * @@ -64,7 +64,8 @@ public static void main(String[] args) { new Coordinate(34.9100, 29.7001), new Coordinate(34.9001, 29.7001)} ); - client.hset("small", toStringMap(singletonMap("geometry", small))); // setting data + // client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geometry", small))); // setting data + client.hset("small", "geometry", small.toString()); // simplified setting data final Polygon large = factory.createPolygon( new Coordinate[]{new Coordinate(34.9001, 29.7001), @@ -72,7 +73,8 @@ public static void main(String[] args) { new Coordinate(34.9200, 29.7001), new Coordinate(34.9001, 29.7001)} ); - client.hset("large", toStringMap(singletonMap("geometry", large))); // setting data + // client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geometry", large))); // setting data + client.hset("large", "geometry", large.toString()); // simplified setting data // searching final Polygon within = factory.createPolygon( @@ -88,14 +90,14 @@ public static void main(String[] args) { .addParam("poly", within) .dialect(3) // DIALECT '3' is required for this query ); - assertEquals(1, res.getTotalResults()); - assertEquals(1, res.getDocuments().size()); + Assert.assertEquals(1, res.getTotalResults()); + Assert.assertEquals(1, res.getDocuments().size()); // We can parse geometry objects with WKTReader try { final WKTReader reader = new WKTReader(); Geometry object = reader.read(res.getDocuments().get(0).getString("geometry")); - assertEquals(small, object); + Assert.assertEquals(small, object); } catch (ParseException ex) { ex.printStackTrace(System.err); } diff --git a/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java b/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java index 792391b775..4ec8416a1a 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java @@ -351,12 +351,12 @@ public void geoShapeFilterSpherical() throws ParseException { final Polygon small = factory.createPolygon(new Coordinate[]{new Coordinate(34.9001, 29.7001), new Coordinate(34.9001, 29.7100), new Coordinate(34.9100, 29.7100), new Coordinate(34.9100, 29.7001), new Coordinate(34.9001, 29.7001)}); - client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geom", small))); + client.hset("small", "geom", small.toString()); final Polygon large = factory.createPolygon(new Coordinate[]{new Coordinate(34.9001, 29.7001), new Coordinate(34.9001, 29.7200), new Coordinate(34.9200, 29.7200), new Coordinate(34.9200, 29.7001), new Coordinate(34.9001, 29.7001)}); - client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geom", large))); + client.hset("large", "geom", large.toString()); // within condition final Polygon within = factory.createPolygon(new Coordinate[]{new Coordinate(34.9000, 29.7000), @@ -381,7 +381,7 @@ public void geoShapeFilterSpherical() throws ParseException { // point type final Point point = factory.createPoint(new Coordinate(34.9010, 29.7010)); - client.hset("point", RediSearchUtil.toStringMap(Collections.singletonMap("geom", point))); + client.hset("point", "geom", point.toString()); res = client.ftSearch(index, "@geom:[within $poly]", FTSearchParams.searchParams().addParam("poly", within).dialect(3)); @@ -399,11 +399,11 @@ public void geoShapeFilterFlat() throws ParseException { // polygon type final Polygon small = factory.createPolygon(new Coordinate[]{new Coordinate(1, 1), new Coordinate(1, 100), new Coordinate(100, 100), new Coordinate(100, 1), new Coordinate(1, 1)}); - client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geom", small))); + client.hset("small", "geom", small.toString()); final Polygon large = factory.createPolygon(new Coordinate[]{new Coordinate(1, 1), new Coordinate(1, 200), new Coordinate(200, 200), new Coordinate(200, 1), new Coordinate(1, 1)}); - client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geom", large))); + client.hset("large", "geom", large.toString()); // within condition final Polygon within = factory.createPolygon(new Coordinate[]{new Coordinate(0, 0), @@ -426,7 +426,7 @@ public void geoShapeFilterFlat() throws ParseException { // point type final Point point = factory.createPoint(new Coordinate(10, 10)); - client.hset("point", RediSearchUtil.toStringMap(Collections.singletonMap("geom", point))); + client.hset("point", "geom", point.toString()); res = client.ftSearch(index, "@geom:[within $poly]", FTSearchParams.searchParams().addParam("poly", within).dialect(3)); @@ -1130,9 +1130,9 @@ public void maxPrefixExpansionSearchProfile() { client.ftConfigSet(configParam, "2"); assertOK(client.ftCreate(index, TextField.of("t"))); - client.hset("1", Collections.singletonMap("t", "foo1")); - client.hset("2", Collections.singletonMap("t", "foo2")); - client.hset("3", Collections.singletonMap("t", "foo3")); + client.hset("1", "t", "foo1"); + client.hset("2", "t", "foo2"); + client.hset("3", "t", "foo3"); Map.Entry> reply = client.ftProfileSearch(index, FTProfileParams.profileParams(), "foo*", FTSearchParams.searchParams().limit(0, 0)); @@ -1152,8 +1152,8 @@ public void maxPrefixExpansionSearchProfile() { @Test public void noContentSearchProfile() { assertOK(client.ftCreate(index, TextField.of("t"))); - client.hset("1", Collections.singletonMap("t", "foo")); - client.hset("2", Collections.singletonMap("t", "bar")); + client.hset("1", "t", "foo"); + client.hset("2", "t", "bar"); Map.Entry> profile = client.ftProfileSearch(index, FTProfileParams.profileParams(), "foo -@t:baz", FTSearchParams.searchParams().noContent()); @@ -1179,8 +1179,8 @@ public void noContentSearchProfile() { @Test public void deepReplySearchProfile() { assertOK(client.ftCreate(index, TextField.of("t"))); - client.hset("1", Collections.singletonMap("t", "hello")); - client.hset("2", Collections.singletonMap("t", "world")); + client.hset("1", "t", "hello"); + client.hset("2", "t", "world"); Map.Entry> profile = client.ftProfileSearch(index, FTProfileParams.profileParams(), @@ -1217,10 +1217,10 @@ public void deepReplySearchProfile() { @Test public void limitedSearchProfile() { assertOK(client.ftCreate(index, TextField.of("t"))); - client.hset("1", Collections.singletonMap("t", "hello")); - client.hset("2", Collections.singletonMap("t", "hell")); - client.hset("3", Collections.singletonMap("t", "help")); - client.hset("4", Collections.singletonMap("t", "helowa")); + client.hset("1", "t", "hello"); + client.hset("2", "t", "hell"); + client.hset("3", "t", "help"); + client.hset("4", "t", "helowa"); Map.Entry> profile = client.ftProfileSearch(index, FTProfileParams.profileParams().limited(), "%hell% hel*", FTSearchParams.searchParams().noContent());