From 0aea49e2a405a1d6a48b46494c9af66b91905218 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 19 Oct 2023 19:22:58 +0600 Subject: [PATCH] Direct FT.CREATE to proper node in LIGHT search mode (#3593) along with some other commands. FT.SEARCH and some other commads were already being directed. --- .../redis/clients/jedis/CommandObjects.java | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 49a9752d98..a7bb226ae5 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -3163,8 +3163,24 @@ private boolean isRoundRobinSearchCommand() { return true; } - private CommandArguments checkAndRoundRobinSearchCommand(CommandArguments commandArguments, String indexName) { - return isRoundRobinSearchCommand() ? commandArguments.add(indexName) : commandArguments.key(indexName); + private CommandArguments checkAndRoundRobinSearchCommand(SearchCommand sc, String idx) { + CommandArguments ca = commandArguments(sc); + if (isRoundRobinSearchCommand()) { + ca.add(idx); + } else { + ca.key(idx); + } + return ca; + } + + private CommandArguments checkAndRoundRobinSearchCommand(SearchCommand sc, String idx1, String idx2) { + CommandArguments ca = commandArguments(sc); + if (isRoundRobinSearchCommand()) { + ca.add(idx1).add(idx2); + } else { + ca.key(idx1).key(idx2); + } + return ca; } private CommandArguments checkAndRoundRobinSearchCommand(CommandArguments commandArguments, byte[] indexName) { @@ -3177,7 +3193,7 @@ private CommandObject directSearchCommand(CommandObject object, String } public final CommandObject ftCreate(String indexName, IndexOptions indexOptions, Schema schema) { - CommandArguments args = commandArguments(SearchCommand.CREATE).add(indexName) + CommandArguments args = checkAndRoundRobinSearchCommand(SearchCommand.CREATE, indexName) .addParams(indexOptions).add(SearchKeyword.SCHEMA); schema.fields.forEach(field -> args.addParams(field)); return new CommandObject<>(args, BuilderFactory.STRING); @@ -3185,38 +3201,38 @@ public final CommandObject ftCreate(String indexName, IndexOptions index public final CommandObject ftCreate(String indexName, FTCreateParams createParams, Iterable schemaFields) { - CommandArguments args = commandArguments(SearchCommand.CREATE).add(indexName) + CommandArguments args = checkAndRoundRobinSearchCommand(SearchCommand.CREATE, indexName) .addParams(createParams).add(SearchKeyword.SCHEMA); schemaFields.forEach(field -> args.addParams(field)); return new CommandObject<>(args, BuilderFactory.STRING); } public final CommandObject ftAlter(String indexName, Schema schema) { - CommandArguments args = commandArguments(SearchCommand.ALTER).add(indexName) + CommandArguments args = checkAndRoundRobinSearchCommand(SearchCommand.ALTER, indexName) .add(SearchKeyword.SCHEMA).add(SearchKeyword.ADD); schema.fields.forEach(field -> args.addParams(field)); return new CommandObject<>(args, BuilderFactory.STRING); } public final CommandObject ftAlter(String indexName, Iterable schemaFields) { - CommandArguments args = commandArguments(SearchCommand.ALTER).add(indexName) + CommandArguments args = checkAndRoundRobinSearchCommand(SearchCommand.ALTER, indexName) .add(SearchKeyword.SCHEMA).add(SearchKeyword.ADD); schemaFields.forEach(field -> args.addParams(field)); return new CommandObject<>(args, BuilderFactory.STRING); } public final CommandObject ftSearch(String indexName, String query) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SEARCH), indexName).add(query), + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SEARCH, indexName).add(query), new SearchResultBuilder(true, false, false, true)); } public final CommandObject ftSearch(String indexName, String query, FTSearchParams params) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SEARCH), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SEARCH, indexName) .add(query).addParams(params), new SearchResultBuilder(!params.getNoContent(), params.getWithScores(), false, true)); } public final CommandObject ftSearch(String indexName, Query query) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SEARCH), indexName).addParams(query), + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SEARCH, indexName).addParams(query), new SearchResultBuilder(!query.getNoContent(), query.getWithScores(), query.getWithPayloads(), true)); } @@ -3226,35 +3242,35 @@ public final CommandObject ftSearch(byte[] indexName, Query query) } public final CommandObject ftExplain(String indexName, Query query) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.EXPLAIN), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.EXPLAIN, indexName) .addParams(query), BuilderFactory.STRING); } public final CommandObject> ftExplainCLI(String indexName, Query query) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.EXPLAINCLI), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.EXPLAINCLI, indexName) .addParams(query), BuilderFactory.STRING_LIST); } public final CommandObject ftAggregate(String indexName, AggregationBuilder aggr) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.AGGREGATE), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.AGGREGATE, indexName) .addObjects(aggr.getArgs()), !aggr.isWithCursor() ? SearchBuilderFactory.SEARCH_AGGREGATION_RESULT : SearchBuilderFactory.SEARCH_AGGREGATION_RESULT_WITH_CURSOR); } public final CommandObject ftCursorRead(String indexName, long cursorId, int count) { return new CommandObject<>(commandArguments(SearchCommand.CURSOR).add(SearchKeyword.READ) - .add(indexName).add(cursorId).add(SearchKeyword.COUNT).add(count), + .key(indexName).add(cursorId).add(SearchKeyword.COUNT).add(count), SearchBuilderFactory.SEARCH_AGGREGATION_RESULT_WITH_CURSOR); } public final CommandObject ftCursorDel(String indexName, long cursorId) { return new CommandObject<>(commandArguments(SearchCommand.CURSOR).add(SearchKeyword.DEL) - .add(indexName).add(cursorId), BuilderFactory.STRING); + .key(indexName).add(cursorId), BuilderFactory.STRING); } public final CommandObject>> ftProfileAggregate( String indexName, FTProfileParams profileParams, AggregationBuilder aggr) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.PROFILE), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.PROFILE, indexName) .add(SearchKeyword.AGGREGATE).addParams(profileParams).add(SearchKeyword.QUERY) .addObjects(aggr.getArgs()), new SearchProfileResponseBuilder<>(!aggr.isWithCursor() ? SearchBuilderFactory.SEARCH_AGGREGATION_RESULT @@ -3263,7 +3279,7 @@ public final CommandObject>> ft public final CommandObject>> ftProfileSearch( String indexName, FTProfileParams profileParams, Query query) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.PROFILE), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.PROFILE, indexName) .add(SearchKeyword.SEARCH).addParams(profileParams).add(SearchKeyword.QUERY) .addParams(query), new SearchProfileResponseBuilder<>(new SearchResultBuilder( !query.getNoContent(), query.getWithScores(), query.getWithPayloads(), true))); @@ -3271,28 +3287,28 @@ public final CommandObject>> ftProfi public final CommandObject>> ftProfileSearch( String indexName, FTProfileParams profileParams, String query, FTSearchParams searchParams) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.PROFILE), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.PROFILE, indexName) .add(SearchKeyword.SEARCH).addParams(profileParams).add(SearchKeyword.QUERY).add(query) .addParams(searchParams), new SearchProfileResponseBuilder<>(new SearchResultBuilder( !searchParams.getNoContent(), searchParams.getWithScores(), false, true))); } public final CommandObject ftDropIndex(String indexName) { - return new CommandObject<>(commandArguments(SearchCommand.DROPINDEX).add(indexName), BuilderFactory.STRING); + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.DROPINDEX, indexName), BuilderFactory.STRING); } public final CommandObject ftDropIndexDD(String indexName) { - return new CommandObject<>(commandArguments(SearchCommand.DROPINDEX).add(indexName).add(SearchKeyword.DD), + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.DROPINDEX, indexName).add(SearchKeyword.DD), BuilderFactory.STRING); } public final CommandObject ftSynUpdate(String indexName, String synonymGroupId, String... terms) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SYNUPDATE), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SYNUPDATE, indexName) .add(synonymGroupId).addObjects((Object[]) terms), BuilderFactory.STRING); } public final CommandObject>> ftSynDump(String indexName) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SYNDUMP), indexName), + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SYNDUMP, indexName), SearchBuilderFactory.SEARCH_SYNONYM_GROUPS); } @@ -3323,36 +3339,36 @@ public final CommandObject> ftDictDumpBySampleKey(String indexName, } public final CommandObject>> ftSpellCheck(String index, String query) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SPELLCHECK), index).add(query), + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SPELLCHECK, index).add(query), SearchBuilderFactory.SEARCH_SPELLCHECK_RESPONSE); } public final CommandObject>> ftSpellCheck(String index, String query, FTSpellCheckParams spellCheckParams) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SPELLCHECK), index).add(query) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SPELLCHECK, index).add(query) .addParams(spellCheckParams), SearchBuilderFactory.SEARCH_SPELLCHECK_RESPONSE); } public final CommandObject> ftInfo(String indexName) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.INFO), indexName), + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.INFO, indexName), BuilderFactory.ENCODED_OBJECT_MAP); } public final CommandObject> ftTagVals(String indexName, String fieldName) { - return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.TAGVALS), indexName) + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.TAGVALS, indexName) .add(fieldName), BuilderFactory.STRING_SET); } public final CommandObject ftAliasAdd(String aliasName, String indexName) { - return new CommandObject<>(commandArguments(SearchCommand.ALIASADD).add(aliasName).add(indexName), BuilderFactory.STRING); + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.ALIASADD, aliasName, indexName), BuilderFactory.STRING); } public final CommandObject ftAliasUpdate(String aliasName, String indexName) { - return new CommandObject<>(commandArguments(SearchCommand.ALIASUPDATE).add(aliasName).add(indexName), BuilderFactory.STRING); + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.ALIASUPDATE, aliasName, indexName), BuilderFactory.STRING); } public final CommandObject ftAliasDel(String aliasName) { - return new CommandObject<>(commandArguments(SearchCommand.ALIASDEL).add(aliasName), BuilderFactory.STRING); + return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.ALIASDEL, aliasName), BuilderFactory.STRING); } public final CommandObject> ftConfigGet(String option) {