diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 89eb3e16ca..5a66f803a8 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -4414,26 +4414,31 @@ public final CommandObject> graphConfigGet(String configName // RedisGraph commands // RedisGears commands + @Deprecated public final CommandObject tFunctionLoad(String libraryCode, TFunctionLoadParams params) { return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.LOAD) .addParams(params).add(libraryCode), BuilderFactory.STRING); } + @Deprecated public final CommandObject tFunctionDelete(String libraryName) { return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.DELETE) .add(libraryName), BuilderFactory.STRING); } + @Deprecated public final CommandObject> tFunctionList(TFunctionListParams params) { return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.LIST) .addParams(params), GearsLibraryInfo.GEARS_LIBRARY_INFO_LIST); } + @Deprecated public final CommandObject tFunctionCall(String library, String function, List keys, List args) { return new CommandObject<>(commandArguments(GearsCommand.TFCALL).add(library + "." + function) .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } + @Deprecated public final CommandObject tFunctionCallAsync(String library, String function, List keys, List args) { return new CommandObject<>(commandArguments(GearsCommand.TFCALLASYNC).add(library + "." + function) .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 9ccf2538b2..db5a52c231 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -5042,26 +5042,31 @@ public Map graphConfigGet(String configName) { // RedisGraph commands // RedisGears commands + @Deprecated @Override public String tFunctionLoad(String libraryCode, TFunctionLoadParams params) { return executeCommand(commandObjects.tFunctionLoad(libraryCode, params)); } + @Deprecated @Override public String tFunctionDelete(String libraryName) { return executeCommand(commandObjects.tFunctionDelete(libraryName)); } + @Deprecated @Override public List tFunctionList(TFunctionListParams params) { return executeCommand(commandObjects.tFunctionList(params)); } + @Deprecated @Override public Object tFunctionCall(String library, String function, List keys, List args) { return executeCommand(commandObjects.tFunctionCall(library, function, keys, args)); } + @Deprecated @Override public Object tFunctionCallAsync(String library, String function, List keys, List args) { return executeCommand(commandObjects.tFunctionCallAsync(library, function, keys, args)); diff --git a/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java b/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java index f5adb42c9e..e196835ab0 100644 --- a/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java +++ b/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java @@ -4,23 +4,24 @@ import java.util.List; +@Deprecated public interface RedisGearsCommands { - default String tFunctionLoad(String libraryCode) { + @Deprecated default String tFunctionLoad(String libraryCode) { return tFunctionLoad(libraryCode, TFunctionLoadParams.loadParams()); } - String tFunctionLoad(String libraryCode, TFunctionLoadParams params); + @Deprecated String tFunctionLoad(String libraryCode, TFunctionLoadParams params); - default List tFunctionList() { + @Deprecated default List tFunctionList() { return tFunctionList(TFunctionListParams.listParams()); } - List tFunctionList(TFunctionListParams params); + @Deprecated List tFunctionList(TFunctionListParams params); - String tFunctionDelete(String libraryName); + @Deprecated String tFunctionDelete(String libraryName); - Object tFunctionCall(String library, String function, List keys, List args); + @Deprecated Object tFunctionCall(String library, String function, List keys, List args); - Object tFunctionCallAsync(String library, String function, List keys, List args); + @Deprecated Object tFunctionCallAsync(String library, String function, List keys, List args); } diff --git a/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java b/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java index fc43f29e66..dfb73b04a9 100644 --- a/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java +++ b/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java @@ -4,13 +4,15 @@ import redis.clients.jedis.commands.ProtocolCommand; import redis.clients.jedis.util.SafeEncoder; +@Deprecated public class RedisGearsProtocol { + @Deprecated public enum GearsCommand implements ProtocolCommand { - TFUNCTION, - TFCALL, - TFCALLASYNC; + @Deprecated TFUNCTION, + @Deprecated TFCALL, + @Deprecated TFCALLASYNC; private final byte[] raw; @@ -24,6 +26,7 @@ public byte[] getRaw() { } } + @Deprecated public enum GearsKeyword implements Rawable { CONFIG, diff --git a/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java b/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java index d3f867e92b..e32bb43639 100644 --- a/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java +++ b/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java @@ -6,6 +6,7 @@ import java.util.Collections; +@Deprecated public class TFunctionListParams implements IParams { private boolean withCode = false; private int verbose; diff --git a/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java b/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java index d155727ec5..b8b0363b6e 100644 --- a/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java +++ b/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java @@ -4,6 +4,7 @@ import redis.clients.jedis.gears.RedisGearsProtocol.GearsKeyword; import redis.clients.jedis.params.IParams; +@Deprecated public class TFunctionLoadParams implements IParams { private boolean replace = false; private String config; diff --git a/src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java b/src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java index ccb8785812..24d47b0e4e 100644 --- a/src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java +++ b/src/main/java/redis/clients/jedis/gears/resps/FunctionInfo.java @@ -10,6 +10,7 @@ import static redis.clients.jedis.BuilderFactory.*; +@Deprecated public class FunctionInfo { private final String name; private final String description; @@ -40,6 +41,7 @@ public FunctionInfo(String name, String description, boolean isAsync, List> FUNCTION_INFO_LIST = new Builder>() { @Override public List build(Object data) { diff --git a/src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java b/src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java index f4b607d6a3..577a0992fc 100644 --- a/src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java +++ b/src/main/java/redis/clients/jedis/gears/resps/FunctionStreamInfo.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.stream.Collectors; +@Deprecated public class FunctionStreamInfo { private final String name; private final String idToReadFrom; @@ -67,6 +68,7 @@ public FunctionStreamInfo(String name, String idToReadFrom, String lastError, this.pendingIds = pendingIds; } + @Deprecated public static final Builder> STREAM_INFO_LIST = new Builder>() { @Override public List build(Object data) { diff --git a/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java b/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java index 5ed6515ff6..d16a607cd2 100644 --- a/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java +++ b/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java @@ -12,6 +12,7 @@ import static redis.clients.jedis.gears.resps.StreamTriggerInfo.STREAM_TRIGGER_INFO_LIST; import static redis.clients.jedis.gears.resps.TriggerInfo.KEYSPACE_TRIGGER_INFO_LIST; +@Deprecated public class GearsLibraryInfo { private final String apiVersion; private final List clusterFunctions; @@ -90,6 +91,7 @@ public String getUser() { return user; } + @Deprecated public static final Builder GEARS_LIBRARY_INFO = new Builder() { @Override public GearsLibraryInfo build(Object data) { @@ -171,6 +173,7 @@ public GearsLibraryInfo build(Object data) { } }; + @Deprecated public static final Builder> GEARS_LIBRARY_INFO_LIST = new Builder>() { @Override public List build(Object data) { diff --git a/src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java b/src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java index be526e0e71..202d4bba4f 100644 --- a/src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java +++ b/src/main/java/redis/clients/jedis/gears/resps/StreamTriggerInfo.java @@ -11,6 +11,7 @@ import static redis.clients.jedis.BuilderFactory.*; import static redis.clients.jedis.gears.resps.FunctionStreamInfo.STREAM_INFO_LIST; +@Deprecated public class StreamTriggerInfo { private final String name; private final String description; @@ -60,6 +61,7 @@ public StreamTriggerInfo(String name, String description, String prefix, this(name, description, prefix, window, trim, Collections.emptyList()); } + @Deprecated public static final Builder> STREAM_TRIGGER_INFO_LIST = new Builder>() { @Override public List build(Object data) { diff --git a/src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java b/src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java index 8a5b470484..775af5cecd 100644 --- a/src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java +++ b/src/main/java/redis/clients/jedis/gears/resps/TriggerInfo.java @@ -11,6 +11,7 @@ import static redis.clients.jedis.BuilderFactory.LONG; import static redis.clients.jedis.BuilderFactory.STRING; +@Deprecated public class TriggerInfo { private final String name; private final String description; @@ -80,6 +81,7 @@ public TriggerInfo(String name, String description, String lastError, long numFi this.totalExecutionTime = totalExecutionTime; } + @Deprecated public static final Builder> KEYSPACE_TRIGGER_INFO_LIST = new Builder>() { @Override public List build(Object data) { diff --git a/src/test/java/io/redis/examples/QueryAggExample.java b/src/test/java/io/redis/examples/QueryAggExample.java new file mode 100644 index 0000000000..786478e5ae --- /dev/null +++ b/src/test/java/io/redis/examples/QueryAggExample.java @@ -0,0 +1,353 @@ +// EXAMPLE: query_agg +// REMOVE_START +package io.redis.examples; + +import org.junit.Assert; +import org.junit.Test; +// REMOVE_END + +// HIDE_START +import java.util.List; +import java.util.ArrayList; +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.json.Path2; +import redis.clients.jedis.search.FTCreateParams; +import redis.clients.jedis.search.IndexDataType; +import redis.clients.jedis.search.schemafields.*; +import redis.clients.jedis.search.aggr.*; +import redis.clients.jedis.exceptions.JedisDataException; +// HIDE_END + +// HIDE_START +public class QueryAggExample { + @Test + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + + //REMOVE_START + // Clear any keys here before using them in tests. + try { jedis.ftDropIndex("idx:bicycle"); } catch (JedisDataException j) {} + //REMOVE_END +// HIDE_END + + SchemaField[] schema = { + TextField.of("$.brand").as("brand"), + TextField.of("$.model").as("model"), + TextField.of("$.description").as("description"), + NumericField.of("$.price").as("price"), + TagField.of("$.condition").as("condition") + }; + + jedis.ftCreate("idx:bicycle", + FTCreateParams.createParams() + .on(IndexDataType.JSON) + .addPrefix("bicycle:"), + schema + ); + + String[] bicycleJsons = new String[] { + " {" + + " \"pickup_zone\": \"POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, " + + "-74.0610 40.6678, -74.0610 40.7578))\"," + + " \"store_location\": \"-74.0060,40.7128\"," + + " \"brand\": \"Velorim\"," + + " \"model\": \"Jigger\"," + + " \"price\": 270," + + " \"description\": \"Small and powerful, the Jigger is the best ride for the smallest of tikes! " + + "This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger " + + "is the vehicle of choice for the rare tenacious little rider raring to go.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-118.2887 34.0972, -118.1987 34.0972, -118.1987 33.9872, " + + "-118.2887 33.9872, -118.2887 34.0972))\"," + + " \"store_location\": \"-118.2437,34.0522\"," + + " \"brand\": \"Bicyk\"," + + " \"model\": \"Hillcraft\"," + + " \"price\": 1200," + + " \"description\": \"Kids want to ride with as little weight as possible. Especially " + + "on an incline! They may be at the age when a 27.5'' wheel bike is just too clumsy coming " + + "off a 24'' bike. The Hillcraft 26 is just the solution they need!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-87.6848 41.9331, -87.5748 41.9331, -87.5748 41.8231, " + + "-87.6848 41.8231, -87.6848 41.9331))\"," + + " \"store_location\": \"-87.6298,41.8781\"," + + " \"brand\": \"Nord\"," + + " \"model\": \"Chook air 5\"," + + " \"price\": 815," + + " \"description\": \"The Chook Air 5 gives kids aged six years and older a durable " + + "and uberlight mountain bike for their first experience on tracks and easy cruising through " + + "forests and fields. The lower top tube makes it easy to mount and dismount in any " + + "situation, giving your kids greater safety on the trails.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-80.2433 25.8067, -80.1333 25.8067, -80.1333 25.6967, " + + "-80.2433 25.6967, -80.2433 25.8067))\"," + + " \"store_location\": \"-80.1918,25.7617\"," + + " \"brand\": \"Eva\"," + + " \"model\": \"Eva 291\"," + + " \"price\": 3400," + + " \"description\": \"The sister company to Nord, Eva launched in 2005 as the first " + + "and only women-dedicated bicycle brand. Designed by women for women, allEva bikes " + + "are optimized for the feminine physique using analytics from a body metrics database. " + + "If you like 29ers, try the Eva 291. It’s a brand new bike for 2022.. This " + + "full-suspension, cross-country ride has been designed for velocity. The 291 has " + + "100mm of front and rear travel, a superlight aluminum frame and fast-rolling " + + "29-inch wheels. Yippee!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-122.4644 37.8199, -122.3544 37.8199, -122.3544 37.7099, " + + "-122.4644 37.7099, -122.4644 37.8199))\"," + + " \"store_location\": \"-122.4194,37.7749\"," + + " \"brand\": \"Noka Bikes\"," + + " \"model\": \"Kahuna\"," + + " \"price\": 3200," + + " \"description\": \"Whether you want to try your hand at XC racing or are looking " + + "for a lively trail bike that's just as inspiring on the climbs as it is over rougher " + + "ground, the Wilder is one heck of a bike built specifically for short women. Both the " + + "frames and components have been tweaked to include a women’s saddle, different bars " + + "and unique colourway.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-0.1778 51.5524, 0.0822 51.5524, 0.0822 51.4024, " + + "-0.1778 51.4024, -0.1778 51.5524))\"," + + " \"store_location\": \"-0.1278,51.5074\"," + + " \"brand\": \"Breakout\"," + + " \"model\": \"XBN 2.1 Alloy\"," + + " \"price\": 810," + + " \"description\": \"The XBN 2.1 Alloy is our entry-level road bike – but that’s " + + "not to say that it’s a basic machine. With an internal weld aluminium frame, a full " + + "carbon fork, and the slick-shifting Claris gears from Shimano’s, this is a bike which " + + "doesn’t break the bank and delivers craved performance.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((2.1767 48.9016, 2.5267 48.9016, 2.5267 48.5516, " + + "2.1767 48.5516, 2.1767 48.9016))\"," + + " \"store_location\": \"2.3522,48.8566\"," + + " \"brand\": \"ScramBikes\"," + + " \"model\": \"WattBike\"," + + " \"price\": 2300," + + " \"description\": \"The WattBike is the best e-bike for people who still " + + "feel young at heart. It has a Bafang 1000W mid-drive system and a 48V 17.5AH " + + "Samsung Lithium-Ion battery, allowing you to ride for more than 60 miles on one " + + "charge. It’s great for tackling hilly terrain or if you just fancy a more " + + "leisurely ride. With three working modes, you can choose between E-bike, " + + "assisted bicycle, and normal bike modes.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((13.3260 52.5700, 13.6550 52.5700, 13.6550 52.2700, " + + "13.3260 52.2700, 13.3260 52.5700))\"," + + " \"store_location\": \"13.4050,52.5200\"," + + " \"brand\": \"Peaknetic\"," + + " \"model\": \"Secto\"," + + " \"price\": 430," + + " \"description\": \"If you struggle with stiff fingers or a kinked neck or " + + "back after a few minutes on the road, this lightweight, aluminum bike alleviates " + + "those issues and allows you to enjoy the ride. From the ergonomic grips to the " + + "lumbar-supporting seat position, the Roll Low-Entry offers incredible comfort. " + + "The rear-inclined seat tube facilitates stability by allowing you to put a foot " + + "on the ground to balance at a stop, and the low step-over frame makes it " + + "accessible for all ability and mobility levels. The saddle is very soft, with " + + "a wide back to support your hip joints and a cutout in the center to redistribute " + + "that pressure. Rim brakes deliver satisfactory braking control, and the wide tires " + + "provide a smooth, stable ride on paved roads and gravel. Rack and fender mounts " + + "facilitate setting up the Roll Low-Entry as your preferred commuter, and the " + + "BMX-like handlebar offers space for mounting a flashlight, bell, or phone holder.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((1.9450 41.4301, 2.4018 41.4301, 2.4018 41.1987, " + + "1.9450 41.1987, 1.9450 41.4301))\"," + + " \"store_location\": \"2.1734, 41.3851\"," + + " \"brand\": \"nHill\"," + + " \"model\": \"Summit\"," + + " \"price\": 1200," + + " \"description\": \"This budget mountain bike from nHill performs well both " + + "on bike paths and on the trail. The fork with 100mm of travel absorbs rough " + + "terrain. Fat Kenda Booster tires give you grip in corners and on wet trails. " + + "The Shimano Tourney drivetrain offered enough gears for finding a comfortable " + + "pace to ride uphill, and the Tektro hydraulic disc brakes break smoothly. " + + "Whether you want an affordable bike that you can take to work, but also take " + + "trail in mountains on the weekends or you’re just after a stable, comfortable " + + "ride for the bike path, the Summit gives a good value for money.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((12.4464 42.1028, 12.5464 42.1028, " + + "12.5464 41.7028, 12.4464 41.7028, 12.4464 42.1028))\"," + + " \"store_location\": \"12.4964,41.9028\"," + + " \"model\": \"ThrillCycle\"," + + " \"brand\": \"BikeShind\"," + + " \"price\": 815," + + " \"description\": \"An artsy, retro-inspired bicycle that’s as " + + "functional as it is pretty: The ThrillCycle steel frame offers a smooth ride. " + + "A 9-speed drivetrain has enough gears for coasting in the city, but we wouldn’t " + + "suggest taking it to the mountains. Fenders protect you from mud, and a rear " + + "basket lets you transport groceries, flowers and books. The ThrillCycle comes " + + "with a limited lifetime warranty, so this little guy will last you long " + + "past graduation.\"," + + " \"condition\": \"refurbished\"" + + " }" + }; + + for (int i = 0; i < bicycleJsons.length; i++) { + jedis.jsonSet("bicycle:" + i, new Path2("$"), bicycleJsons[i]); + } + + // STEP_START agg1 + AggregationResult res1 = jedis.ftAggregate("idx:bicycle", + new AggregationBuilder("@condition:{new}") + .load("__key", "price") + .apply("@price - (@price * 0.1)", "discounted") + ); + + List rows1 = res1.getRows(); + System.out.println(rows1.size()); // >>> 5 + + for (int i = 0; i < rows1.size(); i++) { + System.out.println(rows1.get(i)); + } + // >>> {__key=bicycle:0, discounted=243, price=270} + // >>> {__key=bicycle:5, discounted=729, price=810} + // >>> {__key=bicycle:6, discounted=2070, price=2300} + // >>> {__key=bicycle:7, discounted=387, price=430} + // >>> {__key=bicycle:8, discounted=1080, price=1200} + // STEP_END + + // Tests for 'agg1' step. + // REMOVE_START + Assert.assertEquals(5, rows1.size()); + Assert.assertEquals("{__key=bicycle:0, discounted=243, price=270}", rows1.get(0).toString()); + Assert.assertEquals("{__key=bicycle:5, discounted=729, price=810}", rows1.get(1).toString()); + Assert.assertEquals("{__key=bicycle:6, discounted=2070, price=2300}", rows1.get(2).toString()); + Assert.assertEquals("{__key=bicycle:7, discounted=387, price=430}", rows1.get(3).toString()); + Assert.assertEquals("{__key=bicycle:8, discounted=1080, price=1200}", rows1.get(4).toString()); + // REMOVE_END + + + // STEP_START agg2 + AggregationResult res2 = jedis.ftAggregate("idx:bicycle", + new AggregationBuilder("*") + .load("price") + .apply("@price<1000", "price_category") + .groupBy("@condition", + Reducers.sum("@price_category").as("num_affordable")) + ); + + List rows2 = res2.getRows(); + System.out.println(rows2.size()); // >>> 3 + + for (int i = 0; i < rows2.size(); i++) { + System.out.println(rows2.get(i)); + } + // >>> {condition=refurbished, num_affordable=1} + // >>> {condition=used, num_affordable=1} + // >>> {condition=new, num_affordable=3} + // STEP_END + + // Tests for 'agg2' step. + // REMOVE_START + Assert.assertEquals(3, rows2.size()); + Assert.assertEquals("{condition=refurbished, num_affordable=1}", rows2.get(0).toString()); + Assert.assertEquals("{condition=used, num_affordable=1}", rows2.get(1).toString()); + Assert.assertEquals("{condition=new, num_affordable=3}", rows2.get(2).toString()); + // REMOVE_END + + + // STEP_START agg3 + AggregationResult res3 = jedis.ftAggregate("idx:bicycle", + new AggregationBuilder("*") + .apply("'bicycle'", "type") + .groupBy("@type", Reducers.count().as("num_total")) + ); + + List rows3 = res3.getRows(); + System.out.println(rows3.size()); // >>> 1 + + for (int i = 0; i < rows3.size(); i++) { + System.out.println(rows3.get(i)); + } + // >>> {type=bicycle, num_total=10} + // STEP_END + + // Tests for 'agg3' step. + // REMOVE_START + Assert.assertEquals(1, rows3.size()); + Assert.assertEquals("{type=bicycle, num_total=10}", rows3.get(0).toString()); + // REMOVE_END + + + // STEP_START agg4 + AggregationResult res4 = jedis.ftAggregate("idx:bicycle", + new AggregationBuilder("*") + .load("__key") + .groupBy("@condition", + Reducers.to_list("__key").as("bicycles")) + ); + + List rows4 = res4.getRows(); + System.out.println(rows4.size()); // >>> 3 + + for (int i = 0; i < rows4.size(); i++) { + System.out.println(rows4.get(i)); + } + // >>> {condition=refurbished, bicycles=[bicycle:9]} + // >>> {condition=used, bicycles=[bicycle:3, bicycle:4, bicycle:1, bicycle:2]} + // >>> {condition=new, bicycles=[bicycle:7, bicycle:0, bicycle:5, bicycle:6, bicycle:8]} + // STEP_END + + // Tests for 'agg4' step. + // REMOVE_START + Assert.assertEquals(3, rows4.size()); + + Row test4Row = rows4.get(0); + Assert.assertEquals("refurbished", test4Row.getString("condition")); + + ArrayList test4Bikes = (ArrayList) test4Row.get("bicycles"); + Assert.assertEquals(1, test4Bikes.size()); + Assert.assertTrue(test4Bikes.contains("bicycle:9")); + + test4Row = rows4.get(1); + Assert.assertEquals("used", test4Row.getString("condition")); + + test4Bikes = (ArrayList) test4Row.get("bicycles"); + Assert.assertEquals(4, test4Bikes.size()); + Assert.assertTrue(test4Bikes.contains("bicycle:1")); + Assert.assertTrue(test4Bikes.contains("bicycle:2")); + Assert.assertTrue(test4Bikes.contains("bicycle:3")); + Assert.assertTrue(test4Bikes.contains("bicycle:4")); + + test4Row = rows4.get(2); + Assert.assertEquals("new", test4Row.getString("condition")); + + test4Bikes = (ArrayList) test4Row.get("bicycles"); + Assert.assertEquals(5, test4Bikes.size()); + Assert.assertTrue(test4Bikes.contains("bicycle:0")); + Assert.assertTrue(test4Bikes.contains("bicycle:5")); + Assert.assertTrue(test4Bikes.contains("bicycle:6")); + Assert.assertTrue(test4Bikes.contains("bicycle:7")); + Assert.assertTrue(test4Bikes.contains("bicycle:8")); + // REMOVE_END + +// HIDE_START + jedis.close(); + } +} +// HIDE_END + diff --git a/src/test/java/io/redis/examples/QueryEmExample.java b/src/test/java/io/redis/examples/QueryEmExample.java new file mode 100644 index 0000000000..bd6ab923a8 --- /dev/null +++ b/src/test/java/io/redis/examples/QueryEmExample.java @@ -0,0 +1,325 @@ +// EXAMPLE: query_em +// REMOVE_START +package io.redis.examples; + +import org.junit.Assert; +import org.junit.Test; +// REMOVE_END + +// HIDE_START +import java.util.List; +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.json.Path2; +import redis.clients.jedis.search.*; +import redis.clients.jedis.search.schemafields.*; +import redis.clients.jedis.exceptions.JedisDataException; + +public class QueryEmExample { + @Test + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + + //REMOVE_START + // Clear any keys here before using them in tests. + try {jedis.ftDropIndex("idx:bicycle");} catch (JedisDataException j){} + try {jedis.ftDropIndex("idx:email");} catch (JedisDataException j){} + //REMOVE_END + + SchemaField[] schema = { + TextField.of("$.brand").as("brand"), + TextField.of("$.model").as("model"), + TextField.of("$.description").as("description"), + NumericField.of("$.price").as("price"), + TagField.of("$.condition").as("condition") + }; + + jedis.ftCreate("idx:bicycle", + FTCreateParams.createParams() + .on(IndexDataType.JSON) + .addPrefix("bicycle:"), + schema + ); + + String[] bicycleJsons = new String[] { + " {" + + " \"pickup_zone\": \"POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, " + + "-74.0610 40.6678, -74.0610 40.7578))\"," + + " \"store_location\": \"-74.0060,40.7128\"," + + " \"brand\": \"Velorim\"," + + " \"model\": \"Jigger\"," + + " \"price\": 270," + + " \"description\": \"Small and powerful, the Jigger is the best ride for the smallest of tikes! " + + "This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger " + + "is the vehicle of choice for the rare tenacious little rider raring to go.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-118.2887 34.0972, -118.1987 34.0972, -118.1987 33.9872, " + + "-118.2887 33.9872, -118.2887 34.0972))\"," + + " \"store_location\": \"-118.2437,34.0522\"," + + " \"brand\": \"Bicyk\"," + + " \"model\": \"Hillcraft\"," + + " \"price\": 1200," + + " \"description\": \"Kids want to ride with as little weight as possible. Especially " + + "on an incline! They may be at the age when a 27.5'' wheel bike is just too clumsy coming " + + "off a 24'' bike. The Hillcraft 26 is just the solution they need!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-87.6848 41.9331, -87.5748 41.9331, -87.5748 41.8231, " + + "-87.6848 41.8231, -87.6848 41.9331))\"," + + " \"store_location\": \"-87.6298,41.8781\"," + + " \"brand\": \"Nord\"," + + " \"model\": \"Chook air 5\"," + + " \"price\": 815," + + " \"description\": \"The Chook Air 5 gives kids aged six years and older a durable " + + "and uberlight mountain bike for their first experience on tracks and easy cruising through " + + "forests and fields. The lower top tube makes it easy to mount and dismount in any " + + "situation, giving your kids greater safety on the trails.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-80.2433 25.8067, -80.1333 25.8067, -80.1333 25.6967, " + + "-80.2433 25.6967, -80.2433 25.8067))\"," + + " \"store_location\": \"-80.1918,25.7617\"," + + " \"brand\": \"Eva\"," + + " \"model\": \"Eva 291\"," + + " \"price\": 3400," + + " \"description\": \"The sister company to Nord, Eva launched in 2005 as the first " + + "and only women-dedicated bicycle brand. Designed by women for women, allEva bikes " + + "are optimized for the feminine physique using analytics from a body metrics database. " + + "If you like 29ers, try the Eva 291. It’s a brand new bike for 2022.. This " + + "full-suspension, cross-country ride has been designed for velocity. The 291 has " + + "100mm of front and rear travel, a superlight aluminum frame and fast-rolling " + + "29-inch wheels. Yippee!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-122.4644 37.8199, -122.3544 37.8199, -122.3544 37.7099, " + + "-122.4644 37.7099, -122.4644 37.8199))\"," + + " \"store_location\": \"-122.4194,37.7749\"," + + " \"brand\": \"Noka Bikes\"," + + " \"model\": \"Kahuna\"," + + " \"price\": 3200," + + " \"description\": \"Whether you want to try your hand at XC racing or are looking " + + "for a lively trail bike that's just as inspiring on the climbs as it is over rougher " + + "ground, the Wilder is one heck of a bike built specifically for short women. Both the " + + "frames and components have been tweaked to include a women’s saddle, different bars " + + "and unique colourway.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-0.1778 51.5524, 0.0822 51.5524, 0.0822 51.4024, " + + "-0.1778 51.4024, -0.1778 51.5524))\"," + + " \"store_location\": \"-0.1278,51.5074\"," + + " \"brand\": \"Breakout\"," + + " \"model\": \"XBN 2.1 Alloy\"," + + " \"price\": 810," + + " \"description\": \"The XBN 2.1 Alloy is our entry-level road bike – but that’s " + + "not to say that it’s a basic machine. With an internal weld aluminium frame, a full " + + "carbon fork, and the slick-shifting Claris gears from Shimano’s, this is a bike which " + + "doesn’t break the bank and delivers craved performance.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((2.1767 48.9016, 2.5267 48.9016, 2.5267 48.5516, " + + "2.1767 48.5516, 2.1767 48.9016))\"," + + " \"store_location\": \"2.3522,48.8566\"," + + " \"brand\": \"ScramBikes\"," + + " \"model\": \"WattBike\"," + + " \"price\": 2300," + + " \"description\": \"The WattBike is the best e-bike for people who still " + + "feel young at heart. It has a Bafang 1000W mid-drive system and a 48V 17.5AH " + + "Samsung Lithium-Ion battery, allowing you to ride for more than 60 miles on one " + + "charge. It’s great for tackling hilly terrain or if you just fancy a more " + + "leisurely ride. With three working modes, you can choose between E-bike, " + + "assisted bicycle, and normal bike modes.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((13.3260 52.5700, 13.6550 52.5700, 13.6550 52.2700, " + + "13.3260 52.2700, 13.3260 52.5700))\"," + + " \"store_location\": \"13.4050,52.5200\"," + + " \"brand\": \"Peaknetic\"," + + " \"model\": \"Secto\"," + + " \"price\": 430," + + " \"description\": \"If you struggle with stiff fingers or a kinked neck or " + + "back after a few minutes on the road, this lightweight, aluminum bike alleviates " + + "those issues and allows you to enjoy the ride. From the ergonomic grips to the " + + "lumbar-supporting seat position, the Roll Low-Entry offers incredible comfort. " + + "The rear-inclined seat tube facilitates stability by allowing you to put a foot " + + "on the ground to balance at a stop, and the low step-over frame makes it " + + "accessible for all ability and mobility levels. The saddle is very soft, with " + + "a wide back to support your hip joints and a cutout in the center to redistribute " + + "that pressure. Rim brakes deliver satisfactory braking control, and the wide tires " + + "provide a smooth, stable ride on paved roads and gravel. Rack and fender mounts " + + "facilitate setting up the Roll Low-Entry as your preferred commuter, and the " + + "BMX-like handlebar offers space for mounting a flashlight, bell, or phone holder.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((1.9450 41.4301, 2.4018 41.4301, 2.4018 41.1987, " + + "1.9450 41.1987, 1.9450 41.4301))\"," + + " \"store_location\": \"2.1734, 41.3851\"," + + " \"brand\": \"nHill\"," + + " \"model\": \"Summit\"," + + " \"price\": 1200," + + " \"description\": \"This budget mountain bike from nHill performs well both " + + "on bike paths and on the trail. The fork with 100mm of travel absorbs rough " + + "terrain. Fat Kenda Booster tires give you grip in corners and on wet trails. " + + "The Shimano Tourney drivetrain offered enough gears for finding a comfortable " + + "pace to ride uphill, and the Tektro hydraulic disc brakes break smoothly. " + + "Whether you want an affordable bike that you can take to work, but also take " + + "trail in mountains on the weekends or you’re just after a stable, comfortable " + + "ride for the bike path, the Summit gives a good value for money.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((12.4464 42.1028, 12.5464 42.1028, " + + "12.5464 41.7028, 12.4464 41.7028, 12.4464 42.1028))\"," + + " \"store_location\": \"12.4964,41.9028\"," + + " \"model\": \"ThrillCycle\"," + + " \"brand\": \"BikeShind\"," + + " \"price\": 815," + + " \"description\": \"An artsy, retro-inspired bicycle that’s as " + + "functional as it is pretty: The ThrillCycle steel frame offers a smooth ride. " + + "A 9-speed drivetrain has enough gears for coasting in the city, but we wouldn’t " + + "suggest taking it to the mountains. Fenders protect you from mud, and a rear " + + "basket lets you transport groceries, flowers and books. The ThrillCycle comes " + + "with a limited lifetime warranty, so this little guy will last you long " + + "past graduation.\"," + + " \"condition\": \"refurbished\"" + + " }" + }; + + for (int i = 0; i < bicycleJsons.length; i++) { + jedis.jsonSet("bicycle:" + i, Path2.ROOT_PATH, bicycleJsons[i]); + } +// HIDE_END + + + // STEP_START em1 + SearchResult res1 = jedis.ftSearch("idx:bicycle", "@price:[270 270]"); + System.out.println(res1.getTotalResults()); // >>> 1 + + List docs1 = res1.getDocuments(); + + for (int i = 0; i < docs1.size(); i++) { + System.out.println(docs1.get(i).getId()); + } + // >>> bicycle:0 + + SearchResult res2 = jedis.ftSearch("idx:bicycle", + "*", + FTSearchParams.searchParams() + .filter("price", 270, 270) + ); + System.out.println(res2.getTotalResults()); // >>> 1 + + List docs2 = res2.getDocuments(); + + for (int i = 0; i < docs2.size(); i++) { + System.out.println(docs2.get(i).getId()); + } + // >>> bicycle:0 + // STEP_END + + // Tests for 'em1' step. + // REMOVE_START + Assert.assertEquals(1, res1.getTotalResults()); + Assert.assertEquals("bicycle:0", docs1.get(0).getId()); + + Assert.assertEquals(1, res2.getTotalResults()); + Assert.assertEquals("bicycle:0", docs2.get(0).getId()); + // REMOVE_END + + + // STEP_START em2 + SearchResult res3 = jedis.ftSearch("idx:bicycle", "@condition:{new}"); + System.out.println(res3.getTotalResults()); // >>> 5 + + List docs3 = res3.getDocuments(); + + for (int i = 0; i < docs3.size(); i++) { + System.out.println(docs3.get(i).getId()); + } + // >>> bicycle:5 + // >>> bicycle:0 + // >>> bicycle:6 + // >>> bicycle:7 + // >>> bicycle:8 + // STEP_END + + // Tests for 'em2' step. + // REMOVE_START + Assert.assertEquals(5, res3.getTotalResults()); + Assert.assertEquals("bicycle:5", docs3.get(0).getId()); + Assert.assertEquals("bicycle:0", docs3.get(1).getId()); + Assert.assertEquals("bicycle:6", docs3.get(2).getId()); + Assert.assertEquals("bicycle:7", docs3.get(3).getId()); + Assert.assertEquals("bicycle:8", docs3.get(4).getId()); + // REMOVE_END + + + // STEP_START em3 + SchemaField[] emailSchema = { + TextField.of("$.email").as("email") + }; + + jedis.ftCreate("idx:email", + new FTCreateParams() + .addPrefix("key:") + .on(IndexDataType.JSON), + emailSchema + ); + + jedis.jsonSet("key:1", Path2.ROOT_PATH, "{\"email\": \"test@redis.com\"}"); + + SearchResult res4 = jedis.ftSearch("idx:email", + RediSearchUtil.escapeQuery("@email{test@redis.com}"), + new FTSearchParams().dialect(2) + ); + System.out.println(res4.getTotalResults()); + // STEP_END + + // Tests for 'em3' step. + // REMOVE_START + jedis.ftDropIndex("idx:email"); + // REMOVE_END + + + // STEP_START em4 + SearchResult res5 = jedis.ftSearch("idx:bicycle", + "@description:\"rough terrain\"" + ); + System.out.println(res5.getTotalResults()); // >>> 1 + + List docs5 = res5.getDocuments(); + + for (int i = 0; i < docs5.size(); i++) { + System.out.println(docs5.get(i).getId()); + } + // >>> bicycle:8 + // STEP_END + + // Tests for 'em4' step. + // REMOVE_START + Assert.assertEquals(1, res5.getTotalResults()); + Assert.assertEquals("bicycle:8", docs5.get(0).getId()); + // REMOVE_END + +// HIDE_START + jedis.close(); + } +} +// HIDE_END + diff --git a/src/test/java/io/redis/examples/QueryFtExample.java b/src/test/java/io/redis/examples/QueryFtExample.java new file mode 100644 index 0000000000..aa00300c94 --- /dev/null +++ b/src/test/java/io/redis/examples/QueryFtExample.java @@ -0,0 +1,312 @@ +// EXAMPLE: query_ft +// REMOVE_START +package io.redis.examples; + +import org.junit.Assert; +import org.junit.Test; +// REMOVE_END +// HIDE_START +import java.util.List; +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.search.*; +import redis.clients.jedis.search.schemafields.*; +import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.json.Path2; +// HIDE_END + +// HIDE_START +public class QueryFtExample { + @Test + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + + //REMOVE_START + // Clear any keys here before using them in tests. + try {jedis.ftDropIndex("idx:bicycle");} catch (JedisDataException j){} + //REMOVE_END +// HIDE_END + + SchemaField[] schema = { + TextField.of("$.brand").as("brand"), + TextField.of("$.model").as("model"), + TextField.of("$.description").as("description"), + NumericField.of("$.price").as("price"), + TagField.of("$.condition").as("condition") + }; + + jedis.ftCreate("idx:bicycle", + FTCreateParams.createParams() + .on(IndexDataType.JSON) + .addPrefix("bicycle:"), + schema + ); + + String[] bicycleJsons = new String[] { + " {" + + " \"pickup_zone\": \"POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, " + + "-74.0610 40.6678, -74.0610 40.7578))\"," + + " \"store_location\": \"-74.0060,40.7128\"," + + " \"brand\": \"Velorim\"," + + " \"model\": \"Jigger\"," + + " \"price\": 270," + + " \"description\": \"Small and powerful, the Jigger is the best ride for the smallest of tikes! " + + "This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger " + + "is the vehicle of choice for the rare tenacious little rider raring to go.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-118.2887 34.0972, -118.1987 34.0972, -118.1987 33.9872, " + + "-118.2887 33.9872, -118.2887 34.0972))\"," + + " \"store_location\": \"-118.2437,34.0522\"," + + " \"brand\": \"Bicyk\"," + + " \"model\": \"Hillcraft\"," + + " \"price\": 1200," + + " \"description\": \"Kids want to ride with as little weight as possible. Especially " + + "on an incline! They may be at the age when a 27.5'' wheel bike is just too clumsy coming " + + "off a 24'' bike. The Hillcraft 26 is just the solution they need!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-87.6848 41.9331, -87.5748 41.9331, -87.5748 41.8231, " + + "-87.6848 41.8231, -87.6848 41.9331))\"," + + " \"store_location\": \"-87.6298,41.8781\"," + + " \"brand\": \"Nord\"," + + " \"model\": \"Chook air 5\"," + + " \"price\": 815," + + " \"description\": \"The Chook Air 5 gives kids aged six years and older a durable " + + "and uberlight mountain bike for their first experience on tracks and easy cruising through " + + "forests and fields. The lower top tube makes it easy to mount and dismount in any " + + "situation, giving your kids greater safety on the trails.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-80.2433 25.8067, -80.1333 25.8067, -80.1333 25.6967, " + + "-80.2433 25.6967, -80.2433 25.8067))\"," + + " \"store_location\": \"-80.1918,25.7617\"," + + " \"brand\": \"Eva\"," + + " \"model\": \"Eva 291\"," + + " \"price\": 3400," + + " \"description\": \"The sister company to Nord, Eva launched in 2005 as the first " + + "and only women-dedicated bicycle brand. Designed by women for women, allEva bikes " + + "are optimized for the feminine physique using analytics from a body metrics database. " + + "If you like 29ers, try the Eva 291. It’s a brand new bike for 2022.. This " + + "full-suspension, cross-country ride has been designed for velocity. The 291 has " + + "100mm of front and rear travel, a superlight aluminum frame and fast-rolling " + + "29-inch wheels. Yippee!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-122.4644 37.8199, -122.3544 37.8199, -122.3544 37.7099, " + + "-122.4644 37.7099, -122.4644 37.8199))\"," + + " \"store_location\": \"-122.4194,37.7749\"," + + " \"brand\": \"Noka Bikes\"," + + " \"model\": \"Kahuna\"," + + " \"price\": 3200," + + " \"description\": \"Whether you want to try your hand at XC racing or are looking " + + "for a lively trail bike that's just as inspiring on the climbs as it is over rougher " + + "ground, the Wilder is one heck of a bike built specifically for short women. Both the " + + "frames and components have been tweaked to include a women’s saddle, different bars " + + "and unique colourway.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-0.1778 51.5524, 0.0822 51.5524, 0.0822 51.4024, " + + "-0.1778 51.4024, -0.1778 51.5524))\"," + + " \"store_location\": \"-0.1278,51.5074\"," + + " \"brand\": \"Breakout\"," + + " \"model\": \"XBN 2.1 Alloy\"," + + " \"price\": 810," + + " \"description\": \"The XBN 2.1 Alloy is our entry-level road bike – but that’s " + + "not to say that it’s a basic machine. With an internal weld aluminium frame, a full " + + "carbon fork, and the slick-shifting Claris gears from Shimano’s, this is a bike which " + + "doesn’t break the bank and delivers craved performance.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((2.1767 48.9016, 2.5267 48.9016, 2.5267 48.5516, " + + "2.1767 48.5516, 2.1767 48.9016))\"," + + " \"store_location\": \"2.3522,48.8566\"," + + " \"brand\": \"ScramBikes\"," + + " \"model\": \"WattBike\"," + + " \"price\": 2300," + + " \"description\": \"The WattBike is the best e-bike for people who still " + + "feel young at heart. It has a Bafang 1000W mid-drive system and a 48V 17.5AH " + + "Samsung Lithium-Ion battery, allowing you to ride for more than 60 miles on one " + + "charge. It’s great for tackling hilly terrain or if you just fancy a more " + + "leisurely ride. With three working modes, you can choose between E-bike, " + + "assisted bicycle, and normal bike modes.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((13.3260 52.5700, 13.6550 52.5700, 13.6550 52.2700, " + + "13.3260 52.2700, 13.3260 52.5700))\"," + + " \"store_location\": \"13.4050,52.5200\"," + + " \"brand\": \"Peaknetic\"," + + " \"model\": \"Secto\"," + + " \"price\": 430," + + " \"description\": \"If you struggle with stiff fingers or a kinked neck or " + + "back after a few minutes on the road, this lightweight, aluminum bike alleviates " + + "those issues and allows you to enjoy the ride. From the ergonomic grips to the " + + "lumbar-supporting seat position, the Roll Low-Entry offers incredible comfort. " + + "The rear-inclined seat tube facilitates stability by allowing you to put a foot " + + "on the ground to balance at a stop, and the low step-over frame makes it " + + "accessible for all ability and mobility levels. The saddle is very soft, with " + + "a wide back to support your hip joints and a cutout in the center to redistribute " + + "that pressure. Rim brakes deliver satisfactory braking control, and the wide tires " + + "provide a smooth, stable ride on paved roads and gravel. Rack and fender mounts " + + "facilitate setting up the Roll Low-Entry as your preferred commuter, and the " + + "BMX-like handlebar offers space for mounting a flashlight, bell, or phone holder.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((1.9450 41.4301, 2.4018 41.4301, 2.4018 41.1987, " + + "1.9450 41.1987, 1.9450 41.4301))\"," + + " \"store_location\": \"2.1734, 41.3851\"," + + " \"brand\": \"nHill\"," + + " \"model\": \"Summit\"," + + " \"price\": 1200," + + " \"description\": \"This budget mountain bike from nHill performs well both " + + "on bike paths and on the trail. The fork with 100mm of travel absorbs rough " + + "terrain. Fat Kenda Booster tires give you grip in corners and on wet trails. " + + "The Shimano Tourney drivetrain offered enough gears for finding a comfortable " + + "pace to ride uphill, and the Tektro hydraulic disc brakes break smoothly. " + + "Whether you want an affordable bike that you can take to work, but also take " + + "trail in mountains on the weekends or you’re just after a stable, comfortable " + + "ride for the bike path, the Summit gives a good value for money.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((12.4464 42.1028, 12.5464 42.1028, " + + "12.5464 41.7028, 12.4464 41.7028, 12.4464 42.1028))\"," + + " \"store_location\": \"12.4964,41.9028\"," + + " \"model\": \"ThrillCycle\"," + + " \"brand\": \"BikeShind\"," + + " \"price\": 815," + + " \"description\": \"An artsy, retro-inspired bicycle that’s as " + + "functional as it is pretty: The ThrillCycle steel frame offers a smooth ride. " + + "A 9-speed drivetrain has enough gears for coasting in the city, but we wouldn’t " + + "suggest taking it to the mountains. Fenders protect you from mud, and a rear " + + "basket lets you transport groceries, flowers and books. The ThrillCycle comes " + + "with a limited lifetime warranty, so this little guy will last you long " + + "past graduation.\"," + + " \"condition\": \"refurbished\"" + + " }" + }; + + for (int i = 0; i < bicycleJsons.length; i++) { + jedis.jsonSet("bicycle:" + i, Path2.ROOT_PATH, bicycleJsons[i]); + } + + // STEP_START ft1 + SearchResult res1 = jedis.ftSearch("idx:bicycle", "@description: kids"); + System.out.println(res1.getTotalResults()); // >>> 2 + + List docs1 = res1.getDocuments(); + + for (int i = 0; i < docs1.size(); i++) { + System.out.println(docs1.get(i).getId()); + } + // >>> bicycle:2 + // >>> bicycle:1 + // STEP_END + + // Tests for 'ft1' step. + // REMOVE_START + Assert.assertEquals(2, res1.getTotalResults()); + Assert.assertEquals("bicycle:2", docs1.get(0).getId()); + Assert.assertEquals("bicycle:1", docs1.get(1).getId()); + // REMOVE_END + + + // STEP_START ft2 + SearchResult res2 = jedis.ftSearch("idx:bicycle", "@model: ka*"); + System.out.println(res2.getTotalResults()); // >>> 1 + + List docs2 = res2.getDocuments(); + + for (int i = 0; i < docs2.size(); i++) { + System.out.println(docs2.get(i).getId()); + } + // >>> bicycle:4 + // STEP_END + + // Tests for 'ft2' step. + // REMOVE_START + Assert.assertEquals(1, res2.getTotalResults()); + Assert.assertEquals("bicycle:4", docs2.get(0).getId()); + // REMOVE_END + + + // STEP_START ft3 + SearchResult res3 = jedis.ftSearch("idx:bicycle", "@brand: *bikes"); + System.out.println(res3.getTotalResults()); // >>> 2 + + List docs3 = res3.getDocuments(); + + for (int i = 0; i < docs3.size(); i++) { + System.out.println(docs3.get(i).getId()); + } + // >>> bicycle:6 + // >>> bicycle:4 + // STEP_END + + // Tests for 'ft3' step. + // REMOVE_START + Assert.assertEquals(2, res3.getTotalResults()); + Assert.assertEquals("bicycle:6", docs3.get(0).getId()); + Assert.assertEquals("bicycle:4", docs3.get(1).getId()); + // REMOVE_END + + + // STEP_START ft4 + SearchResult res4 = jedis.ftSearch("idx:bicycle", "%optamized%"); + System.out.println(res4.getTotalResults()); // >>> 1 + + List docs4 = res4.getDocuments(); + + for (int i = 0; i < docs4.size(); i++) { + System.out.println(docs4.get(i).getId()); + } + // >>> bicycle:3 + // STEP_END + + // Tests for 'ft4' step. + // REMOVE_START + Assert.assertEquals(1, res4.getTotalResults()); + Assert.assertEquals("bicycle:3", docs4.get(0).getId()); + // REMOVE_END + + + // STEP_START ft5 + SearchResult res5 = jedis.ftSearch("idx:bicycle", "%%optamised%%"); + System.out.println(res5.getTotalResults()); // >>> 1 + + List docs5 = res5.getDocuments(); + + for (int i = 0; i < docs5.size(); i++) { + System.out.println(docs5.get(i).getId()); + } + // >>> bicycle:3 + // STEP_END + + // Tests for 'ft5' step. + // REMOVE_START + Assert.assertEquals(1, res5.getTotalResults()); + Assert.assertEquals("bicycle:3", docs5.get(0).getId()); + // REMOVE_END + +// HIDE_START + jedis.close(); + } +} +// HIDE_END + diff --git a/src/test/java/io/redis/examples/QueryGeoExample.java b/src/test/java/io/redis/examples/QueryGeoExample.java new file mode 100644 index 0000000000..47b93f7579 --- /dev/null +++ b/src/test/java/io/redis/examples/QueryGeoExample.java @@ -0,0 +1,299 @@ +// EXAMPLE: query_geo +// REMOVE_START +package io.redis.examples; + +import org.junit.Assert; +import org.junit.Test; +// REMOVE_END +// HIDE_START +import java.util.List; +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.search.*; +import redis.clients.jedis.search.schemafields.*; +import redis.clients.jedis.search.schemafields.GeoShapeField.CoordinateSystem; +import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.json.Path2; +// HIDE_END + +// HIDE_START +public class QueryGeoExample { + @Test + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + + //REMOVE_START + // Clear any keys here before using them in tests. + try { jedis.ftDropIndex("idx:bicycle"); } catch (JedisDataException j) {} + //REMOVE_END +// HIDE_END + + SchemaField[] schema = { + TextField.of("$.brand").as("brand"), + TextField.of("$.model").as("model"), + TextField.of("$.description").as("description"), + NumericField.of("$.price").as("price"), + TagField.of("$.condition").as("condition"), + GeoField.of("$.store_location").as("store_location"), + GeoShapeField.of("$.pickup_zone", CoordinateSystem.FLAT).as("pickup_zone") + }; + + jedis.ftCreate("idx:bicycle", + FTCreateParams.createParams() + .on(IndexDataType.JSON) + .addPrefix("bicycle:"), + schema + ); + + String[] bicycleJsons = new String[] { + " {" + + " \"pickup_zone\": \"POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, " + + "-74.0610 40.6678, -74.0610 40.7578))\"," + + " \"store_location\": \"-74.0060,40.7128\"," + + " \"brand\": \"Velorim\"," + + " \"model\": \"Jigger\"," + + " \"price\": 270," + + " \"description\": \"Small and powerful, the Jigger is the best ride for the smallest of tikes! " + + "This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger " + + "is the vehicle of choice for the rare tenacious little rider raring to go.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-118.2887 34.0972, -118.1987 34.0972, -118.1987 33.9872, " + + "-118.2887 33.9872, -118.2887 34.0972))\"," + + " \"store_location\": \"-118.2437,34.0522\"," + + " \"brand\": \"Bicyk\"," + + " \"model\": \"Hillcraft\"," + + " \"price\": 1200," + + " \"description\": \"Kids want to ride with as little weight as possible. Especially " + + "on an incline! They may be at the age when a 27.5'' wheel bike is just too clumsy coming " + + "off a 24'' bike. The Hillcraft 26 is just the solution they need!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-87.6848 41.9331, -87.5748 41.9331, -87.5748 41.8231, " + + "-87.6848 41.8231, -87.6848 41.9331))\"," + + " \"store_location\": \"-87.6298,41.8781\"," + + " \"brand\": \"Nord\"," + + " \"model\": \"Chook air 5\"," + + " \"price\": 815," + + " \"description\": \"The Chook Air 5 gives kids aged six years and older a durable " + + "and uberlight mountain bike for their first experience on tracks and easy cruising through " + + "forests and fields. The lower top tube makes it easy to mount and dismount in any " + + "situation, giving your kids greater safety on the trails.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-80.2433 25.8067, -80.1333 25.8067, -80.1333 25.6967, " + + "-80.2433 25.6967, -80.2433 25.8067))\"," + + " \"store_location\": \"-80.1918,25.7617\"," + + " \"brand\": \"Eva\"," + + " \"model\": \"Eva 291\"," + + " \"price\": 3400," + + " \"description\": \"The sister company to Nord, Eva launched in 2005 as the first " + + "and only women-dedicated bicycle brand. Designed by women for women, allEva bikes " + + "are optimized for the feminine physique using analytics from a body metrics database. " + + "If you like 29ers, try the Eva 291. It’s a brand new bike for 2022.. This " + + "full-suspension, cross-country ride has been designed for velocity. The 291 has " + + "100mm of front and rear travel, a superlight aluminum frame and fast-rolling " + + "29-inch wheels. Yippee!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-122.4644 37.8199, -122.3544 37.8199, -122.3544 37.7099, " + + "-122.4644 37.7099, -122.4644 37.8199))\"," + + " \"store_location\": \"-122.4194,37.7749\"," + + " \"brand\": \"Noka Bikes\"," + + " \"model\": \"Kahuna\"," + + " \"price\": 3200," + + " \"description\": \"Whether you want to try your hand at XC racing or are looking " + + "for a lively trail bike that's just as inspiring on the climbs as it is over rougher " + + "ground, the Wilder is one heck of a bike built specifically for short women. Both the " + + "frames and components have been tweaked to include a women’s saddle, different bars " + + "and unique colourway.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-0.1778 51.5524, 0.0822 51.5524, 0.0822 51.4024, " + + "-0.1778 51.4024, -0.1778 51.5524))\"," + + " \"store_location\": \"-0.1278,51.5074\"," + + " \"brand\": \"Breakout\"," + + " \"model\": \"XBN 2.1 Alloy\"," + + " \"price\": 810," + + " \"description\": \"The XBN 2.1 Alloy is our entry-level road bike – but that’s " + + "not to say that it’s a basic machine. With an internal weld aluminium frame, a full " + + "carbon fork, and the slick-shifting Claris gears from Shimano’s, this is a bike which " + + "doesn’t break the bank and delivers craved performance.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((2.1767 48.9016, 2.5267 48.9016, 2.5267 48.5516, " + + "2.1767 48.5516, 2.1767 48.9016))\"," + + " \"store_location\": \"2.3522,48.8566\"," + + " \"brand\": \"ScramBikes\"," + + " \"model\": \"WattBike\"," + + " \"price\": 2300," + + " \"description\": \"The WattBike is the best e-bike for people who still " + + "feel young at heart. It has a Bafang 1000W mid-drive system and a 48V 17.5AH " + + "Samsung Lithium-Ion battery, allowing you to ride for more than 60 miles on one " + + "charge. It’s great for tackling hilly terrain or if you just fancy a more " + + "leisurely ride. With three working modes, you can choose between E-bike, " + + "assisted bicycle, and normal bike modes.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((13.3260 52.5700, 13.6550 52.5700, 13.6550 52.2700, " + + "13.3260 52.2700, 13.3260 52.5700))\"," + + " \"store_location\": \"13.4050,52.5200\"," + + " \"brand\": \"Peaknetic\"," + + " \"model\": \"Secto\"," + + " \"price\": 430," + + " \"description\": \"If you struggle with stiff fingers or a kinked neck or " + + "back after a few minutes on the road, this lightweight, aluminum bike alleviates " + + "those issues and allows you to enjoy the ride. From the ergonomic grips to the " + + "lumbar-supporting seat position, the Roll Low-Entry offers incredible comfort. " + + "The rear-inclined seat tube facilitates stability by allowing you to put a foot " + + "on the ground to balance at a stop, and the low step-over frame makes it " + + "accessible for all ability and mobility levels. The saddle is very soft, with " + + "a wide back to support your hip joints and a cutout in the center to redistribute " + + "that pressure. Rim brakes deliver satisfactory braking control, and the wide tires " + + "provide a smooth, stable ride on paved roads and gravel. Rack and fender mounts " + + "facilitate setting up the Roll Low-Entry as your preferred commuter, and the " + + "BMX-like handlebar offers space for mounting a flashlight, bell, or phone holder.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((1.9450 41.4301, 2.4018 41.4301, 2.4018 41.1987, " + + "1.9450 41.1987, 1.9450 41.4301))\"," + + " \"store_location\": \"2.1734, 41.3851\"," + + " \"brand\": \"nHill\"," + + " \"model\": \"Summit\"," + + " \"price\": 1200," + + " \"description\": \"This budget mountain bike from nHill performs well both " + + "on bike paths and on the trail. The fork with 100mm of travel absorbs rough " + + "terrain. Fat Kenda Booster tires give you grip in corners and on wet trails. " + + "The Shimano Tourney drivetrain offered enough gears for finding a comfortable " + + "pace to ride uphill, and the Tektro hydraulic disc brakes break smoothly. " + + "Whether you want an affordable bike that you can take to work, but also take " + + "trail in mountains on the weekends or you’re just after a stable, comfortable " + + "ride for the bike path, the Summit gives a good value for money.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((12.4464 42.1028, 12.5464 42.1028, " + + "12.5464 41.7028, 12.4464 41.7028, 12.4464 42.1028))\"," + + " \"store_location\": \"12.4964,41.9028\"," + + " \"model\": \"ThrillCycle\"," + + " \"brand\": \"BikeShind\"," + + " \"price\": 815," + + " \"description\": \"An artsy, retro-inspired bicycle that’s as " + + "functional as it is pretty: The ThrillCycle steel frame offers a smooth ride. " + + "A 9-speed drivetrain has enough gears for coasting in the city, but we wouldn’t " + + "suggest taking it to the mountains. Fenders protect you from mud, and a rear " + + "basket lets you transport groceries, flowers and books. The ThrillCycle comes " + + "with a limited lifetime warranty, so this little guy will last you long " + + "past graduation.\"," + + " \"condition\": \"refurbished\"" + + " }" + }; + + for (int i = 0; i < bicycleJsons.length; i++) { + jedis.jsonSet("bicycle:" + i, Path2.ROOT_PATH, bicycleJsons[i]); + } + + // STEP_START geo1 + SearchResult res1 = jedis.ftSearch("idx:bicycle", + "@store_location:[$lon $lat $radius $units]", + FTSearchParams.searchParams() + .addParam("lon", -0.1778) + .addParam("lat", 51.5524) + .addParam("radius", 20) + .addParam("units", "mi") + .dialect(2) + ); + System.out.println(res1.getTotalResults()); // >>> 1 + + List docs1 = res1.getDocuments(); + + for (int i = 0; i < docs1.size(); i++) { + System.out.println(docs1.get(i).getId()); + } + // >>> bicycle:5 + // STEP_END + + // Tests for 'geo1' step. + // REMOVE_START + Assert.assertEquals(1, res1.getTotalResults()); + Assert.assertEquals("bicycle:5", docs1.get(0).getId()); + // REMOVE_END + + + // STEP_START geo2 + SearchResult res2 = jedis.ftSearch("idx:bicycle", + "@pickup_zone:[CONTAINS $bike]", + FTSearchParams.searchParams() + .addParam("bike", "POINT(-0.1278 51.5074)") + .dialect(3) + ); + System.out.println(res2.getTotalResults()); // >>> 1 + + List docs2 = res2.getDocuments(); + + for (int i = 0; i < docs2.size(); i++) { + System.out.println(docs2.get(i).getId()); + } + // >>> bicycle:5 + // STEP_END + + // Tests for 'geo2' step. + // REMOVE_START + Assert.assertEquals(1, res2.getTotalResults()); + Assert.assertEquals("bicycle:5", docs2.get(0).getId()); + // REMOVE_END + + + // STEP_START geo3 + SearchResult res3 = jedis.ftSearch("idx:bicycle", + "@pickup_zone:[WITHIN $europe]", + FTSearchParams.searchParams() + .addParam("europe", "POLYGON((-25 35, 40 35, 40 70, -25 70, -25 35))") + .dialect(3) + ); + System.out.println(res3.getTotalResults()); // >>> 5 + + List docs3 = res3.getDocuments(); + + for (int i = 0; i < docs3.size(); i++) { + System.out.println(docs3.get(i).getId()); + } + // >>> bicycle:5 + // >>> bicycle:6 + // >>> bicycle:7 + // >>> bicycle:8 + // >>> bicycle:9 + // STEP_END + + // Tests for 'geo3' step. + // REMOVE_START + Assert.assertEquals(5, res3.getTotalResults()); + Assert.assertEquals("bicycle:5", docs3.get(0).getId()); + Assert.assertEquals("bicycle:6", docs3.get(1).getId()); + Assert.assertEquals("bicycle:7", docs3.get(2).getId()); + Assert.assertEquals("bicycle:8", docs3.get(3).getId()); + Assert.assertEquals("bicycle:9", docs3.get(4).getId()); + // REMOVE_END + +// HIDE_START + jedis.close(); + } +} +// HIDE_END + diff --git a/src/test/java/io/redis/examples/QueryRangeExample.java b/src/test/java/io/redis/examples/QueryRangeExample.java new file mode 100644 index 0000000000..5e4edf4d49 --- /dev/null +++ b/src/test/java/io/redis/examples/QueryRangeExample.java @@ -0,0 +1,331 @@ +// EXAMPLE: query_range +// REMOVE_START +package io.redis.examples; + +import org.junit.Assert; +import org.junit.Test; + +// REMOVE_END +// HIDE_START +import java.util.List; +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.search.*; +import redis.clients.jedis.search.schemafields.*; +import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.json.Path2; +import redis.clients.jedis.args.SortingOrder; +// HIDE_END + + + +// HIDE_START +public class QueryRangeExample { + @Test + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + + //REMOVE_START + // Clear any keys here before using them in tests. + try { jedis.ftDropIndex("idx:bicycle"); } catch (JedisDataException j) {} + //REMOVE_END + + SchemaField[] schema = { + TextField.of("$.brand").as("brand"), + TextField.of("$.model").as("model"), + TextField.of("$.description").as("description"), + NumericField.of("$.price").as("price"), + TagField.of("$.condition").as("condition") + }; + + jedis.ftCreate("idx:bicycle", + FTCreateParams.createParams() + .on(IndexDataType.JSON) + .addPrefix("bicycle:"), + schema + ); + + String[] bicycleJsons = new String[] { + " {" + + " \"pickup_zone\": \"POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, " + + "-74.0610 40.6678, -74.0610 40.7578))\"," + + " \"store_location\": \"-74.0060,40.7128\"," + + " \"brand\": \"Velorim\"," + + " \"model\": \"Jigger\"," + + " \"price\": 270," + + " \"description\": \"Small and powerful, the Jigger is the best ride for the smallest of tikes! " + + "This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger " + + "is the vehicle of choice for the rare tenacious little rider raring to go.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-118.2887 34.0972, -118.1987 34.0972, -118.1987 33.9872, " + + "-118.2887 33.9872, -118.2887 34.0972))\"," + + " \"store_location\": \"-118.2437,34.0522\"," + + " \"brand\": \"Bicyk\"," + + " \"model\": \"Hillcraft\"," + + " \"price\": 1200," + + " \"description\": \"Kids want to ride with as little weight as possible. Especially " + + "on an incline! They may be at the age when a 27.5'' wheel bike is just too clumsy coming " + + "off a 24'' bike. The Hillcraft 26 is just the solution they need!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-87.6848 41.9331, -87.5748 41.9331, -87.5748 41.8231, " + + "-87.6848 41.8231, -87.6848 41.9331))\"," + + " \"store_location\": \"-87.6298,41.8781\"," + + " \"brand\": \"Nord\"," + + " \"model\": \"Chook air 5\"," + + " \"price\": 815," + + " \"description\": \"The Chook Air 5 gives kids aged six years and older a durable " + + "and uberlight mountain bike for their first experience on tracks and easy cruising through " + + "forests and fields. The lower top tube makes it easy to mount and dismount in any " + + "situation, giving your kids greater safety on the trails.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-80.2433 25.8067, -80.1333 25.8067, -80.1333 25.6967, " + + "-80.2433 25.6967, -80.2433 25.8067))\"," + + " \"store_location\": \"-80.1918,25.7617\"," + + " \"brand\": \"Eva\"," + + " \"model\": \"Eva 291\"," + + " \"price\": 3400," + + " \"description\": \"The sister company to Nord, Eva launched in 2005 as the first " + + "and only women-dedicated bicycle brand. Designed by women for women, allEva bikes " + + "are optimized for the feminine physique using analytics from a body metrics database. " + + "If you like 29ers, try the Eva 291. It’s a brand new bike for 2022.. This " + + "full-suspension, cross-country ride has been designed for velocity. The 291 has " + + "100mm of front and rear travel, a superlight aluminum frame and fast-rolling " + + "29-inch wheels. Yippee!\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-122.4644 37.8199, -122.3544 37.8199, -122.3544 37.7099, " + + "-122.4644 37.7099, -122.4644 37.8199))\"," + + " \"store_location\": \"-122.4194,37.7749\"," + + " \"brand\": \"Noka Bikes\"," + + " \"model\": \"Kahuna\"," + + " \"price\": 3200," + + " \"description\": \"Whether you want to try your hand at XC racing or are looking " + + "for a lively trail bike that's just as inspiring on the climbs as it is over rougher " + + "ground, the Wilder is one heck of a bike built specifically for short women. Both the " + + "frames and components have been tweaked to include a women’s saddle, different bars " + + "and unique colourway.\"," + + " \"condition\": \"used\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((-0.1778 51.5524, 0.0822 51.5524, 0.0822 51.4024, " + + "-0.1778 51.4024, -0.1778 51.5524))\"," + + " \"store_location\": \"-0.1278,51.5074\"," + + " \"brand\": \"Breakout\"," + + " \"model\": \"XBN 2.1 Alloy\"," + + " \"price\": 810," + + " \"description\": \"The XBN 2.1 Alloy is our entry-level road bike – but that’s " + + "not to say that it’s a basic machine. With an internal weld aluminium frame, a full " + + "carbon fork, and the slick-shifting Claris gears from Shimano’s, this is a bike which " + + "doesn’t break the bank and delivers craved performance.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((2.1767 48.9016, 2.5267 48.9016, 2.5267 48.5516, " + + "2.1767 48.5516, 2.1767 48.9016))\"," + + " \"store_location\": \"2.3522,48.8566\"," + + " \"brand\": \"ScramBikes\"," + + " \"model\": \"WattBike\"," + + " \"price\": 2300," + + " \"description\": \"The WattBike is the best e-bike for people who still " + + "feel young at heart. It has a Bafang 1000W mid-drive system and a 48V 17.5AH " + + "Samsung Lithium-Ion battery, allowing you to ride for more than 60 miles on one " + + "charge. It’s great for tackling hilly terrain or if you just fancy a more " + + "leisurely ride. With three working modes, you can choose between E-bike, " + + "assisted bicycle, and normal bike modes.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((13.3260 52.5700, 13.6550 52.5700, 13.6550 52.2700, " + + "13.3260 52.2700, 13.3260 52.5700))\"," + + " \"store_location\": \"13.4050,52.5200\"," + + " \"brand\": \"Peaknetic\"," + + " \"model\": \"Secto\"," + + " \"price\": 430," + + " \"description\": \"If you struggle with stiff fingers or a kinked neck or " + + "back after a few minutes on the road, this lightweight, aluminum bike alleviates " + + "those issues and allows you to enjoy the ride. From the ergonomic grips to the " + + "lumbar-supporting seat position, the Roll Low-Entry offers incredible comfort. " + + "The rear-inclined seat tube facilitates stability by allowing you to put a foot " + + "on the ground to balance at a stop, and the low step-over frame makes it " + + "accessible for all ability and mobility levels. The saddle is very soft, with " + + "a wide back to support your hip joints and a cutout in the center to redistribute " + + "that pressure. Rim brakes deliver satisfactory braking control, and the wide tires " + + "provide a smooth, stable ride on paved roads and gravel. Rack and fender mounts " + + "facilitate setting up the Roll Low-Entry as your preferred commuter, and the " + + "BMX-like handlebar offers space for mounting a flashlight, bell, or phone holder.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((1.9450 41.4301, 2.4018 41.4301, 2.4018 41.1987, " + + "1.9450 41.1987, 1.9450 41.4301))\"," + + " \"store_location\": \"2.1734, 41.3851\"," + + " \"brand\": \"nHill\"," + + " \"model\": \"Summit\"," + + " \"price\": 1200," + + " \"description\": \"This budget mountain bike from nHill performs well both " + + "on bike paths and on the trail. The fork with 100mm of travel absorbs rough " + + "terrain. Fat Kenda Booster tires give you grip in corners and on wet trails. " + + "The Shimano Tourney drivetrain offered enough gears for finding a comfortable " + + "pace to ride uphill, and the Tektro hydraulic disc brakes break smoothly. " + + "Whether you want an affordable bike that you can take to work, but also take " + + "trail in mountains on the weekends or you’re just after a stable, comfortable " + + "ride for the bike path, the Summit gives a good value for money.\"," + + " \"condition\": \"new\"" + + " }", + + " {" + + " \"pickup_zone\": \"POLYGON((12.4464 42.1028, 12.5464 42.1028, " + + "12.5464 41.7028, 12.4464 41.7028, 12.4464 42.1028))\"," + + " \"store_location\": \"12.4964,41.9028\"," + + " \"model\": \"ThrillCycle\"," + + " \"brand\": \"BikeShind\"," + + " \"price\": 815," + + " \"description\": \"An artsy, retro-inspired bicycle that’s as " + + "functional as it is pretty: The ThrillCycle steel frame offers a smooth ride. " + + "A 9-speed drivetrain has enough gears for coasting in the city, but we wouldn’t " + + "suggest taking it to the mountains. Fenders protect you from mud, and a rear " + + "basket lets you transport groceries, flowers and books. The ThrillCycle comes " + + "with a limited lifetime warranty, so this little guy will last you long " + + "past graduation.\"," + + " \"condition\": \"refurbished\"" + + " }" + }; + + for (int i = 0; i < bicycleJsons.length; i++) { + jedis.jsonSet("bicycle:" + i, Path2.ROOT_PATH, bicycleJsons[i]); + } +// HIDE_END + + + // STEP_START range1 + SearchResult res1 = jedis.ftSearch("idx:bicycle", "@price:[500 1000]"); + System.out.println(res1.getTotalResults()); // >>> 3 + + List docs1 = res1.getDocuments(); + + for (int i = 0; i < docs1.size(); i++) { + System.out.println(docs1.get(i).getId()); + } + // >>> bicycle:2 + // >>> bicycle:5 + // >>> bicycle:9 + // STEP_END + + // Tests for 'range1' step. + // REMOVE_START + Assert.assertEquals(3, res1.getTotalResults()); + Assert.assertEquals("bicycle:2", docs1.get(0).getId()); + Assert.assertEquals("bicycle:5", docs1.get(1).getId()); + Assert.assertEquals("bicycle:9", docs1.get(2).getId()); + // REMOVE_END + + + // STEP_START range2 + SearchResult res2 = jedis.ftSearch("idx:bicycle", + "*", + FTSearchParams.searchParams() + .filter("price", 500, 1000) + ); + System.out.println(res2.getTotalResults()); // >>> 3 + + List docs2 = res2.getDocuments(); + + for (int i = 0; i < docs2.size(); i++) { + System.out.println(docs2.get(i).getId()); + } + // >>> bicycle:2 + // >>> bicycle:5 + // >>> bicycle:9 + // STEP_END + + // Tests for 'range2' step. + // REMOVE_START + Assert.assertEquals(3, res2.getTotalResults()); + Assert.assertEquals("bicycle:2", docs2.get(0).getId()); + Assert.assertEquals("bicycle:5", docs2.get(1).getId()); + Assert.assertEquals("bicycle:9", docs2.get(2).getId()); + // REMOVE_END + + + // STEP_START range3 + SearchResult res3 = jedis.ftSearch("idx:bicycle", + "*", + FTSearchParams.searchParams() + .filter("price", 1000, true, Double.POSITIVE_INFINITY, false) + ); + System.out.println(res3.getTotalResults()); // >>> 5 + + List docs3 = res3.getDocuments(); + + for (int i = 0; i < docs3.size(); i++) { + System.out.println(docs3.get(i).getId()); + } + // >>> bicycle:1 + // >>> bicycle:4 + // >>> bicycle:6 + // >>> bicycle:3 + // >>> bicycle:8 + // STEP_END + + // Tests for 'range3' step. + // REMOVE_START + Assert.assertEquals(5, res3.getTotalResults()); + Assert.assertEquals("bicycle:1", docs3.get(0).getId()); + Assert.assertEquals("bicycle:4", docs3.get(1).getId()); + Assert.assertEquals("bicycle:6", docs3.get(2).getId()); + Assert.assertEquals("bicycle:3", docs3.get(3).getId()); + Assert.assertEquals("bicycle:8", docs3.get(4).getId()); + // REMOVE_END + + + // STEP_START range4 + SearchResult res4 = jedis.ftSearch("idx:bicycle", + "@price:[-inf 2000]", + FTSearchParams.searchParams() + .sortBy("price", SortingOrder.ASC) + .limit(0, 5) + ); + System.out.println(res4.getTotalResults()); // >>> 7 + + List docs4 = res4.getDocuments(); + + for (int i = 0; i < docs4.size(); i++) { + System.out.println(docs4.get(i).getId()); + } + // >>> bicycle:0 + // >>> bicycle:7 + // >>> bicycle:5 + // >>> bicycle:2 + // >>> bicycle:9 + // STEP_END + + // Tests for 'range4' step. + // REMOVE_START + Assert.assertEquals(7, res4.getTotalResults()); + Assert.assertEquals("bicycle:0", docs4.get(0).getId()); + Assert.assertEquals("bicycle:7", docs4.get(1).getId()); + Assert.assertEquals("bicycle:5", docs4.get(2).getId()); + Assert.assertEquals("bicycle:2", docs4.get(3).getId()); + Assert.assertEquals("bicycle:9", docs4.get(4).getId()); + // REMOVE_END + +// HIDE_START + jedis.close(); + } +} +// HIDE_END + diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java index 6403f57404..ce198f4627 100644 --- a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsTriggersAndFunctionsCommandsTest.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; import org.junit.After; +import org.junit.Ignore; import org.junit.Test; import redis.clients.jedis.RedisProtocol; @@ -19,6 +20,7 @@ /** * Tests related to Triggers and functions commands. */ +@Ignore public class CommandObjectsTriggersAndFunctionsCommandsTest extends CommandObjectsModulesTestBase { public CommandObjectsTriggersAndFunctionsCommandsTest(RedisProtocol protocol) { diff --git a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java index 5dec794c65..62fd7bf7cd 100644 --- a/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java +++ b/src/test/java/redis/clients/jedis/mocked/unified/UnifiedJedisTriggersAndFunctionsCommandsTest.java @@ -9,12 +9,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; - +import org.junit.Ignore; import org.junit.Test; import redis.clients.jedis.gears.TFunctionListParams; import redis.clients.jedis.gears.TFunctionLoadParams; import redis.clients.jedis.gears.resps.GearsLibraryInfo; +@Ignore public class UnifiedJedisTriggersAndFunctionsCommandsTest extends UnifiedJedisMockedTestBase { @Test diff --git a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java index 117094b9b8..e32e526279 100644 --- a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java +++ b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java @@ -1,9 +1,19 @@ package redis.clients.jedis.modules.gears; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import org.hamcrest.Matchers; import org.junit.After; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -15,15 +25,6 @@ import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.gears.resps.GearsLibraryInfo; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -31,6 +32,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +@Ignore @RunWith(Parameterized.class) public class GearsTest extends RedisModuleCommandsTestBase {