Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Direct FT.CREATE to proper node in LIGHT search mode #3593

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 44 additions & 28 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -3118,8 +3118,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) {
Expand All @@ -3132,68 +3148,68 @@ private <T> CommandObject<T> directSearchCommand(CommandObject<T> object, String
}

public final CommandObject<String> 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);
}

public final CommandObject<String> ftCreate(String indexName, FTCreateParams createParams,
Iterable<SchemaField> 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<String> 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<String> ftAlter(String indexName, Iterable<SchemaField> 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<String> 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<String> 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<String> 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<String> 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<String> 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<SearchResult> ftSearch(String indexName, String query) {
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SEARCH), indexName).add(query),
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SEARCH, indexName).add(query),
getSearchResultBuilder(() -> new SearchResultBuilder(true, false, true)));
}

public final CommandObject<SearchResult> 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.dialectOptional(searchDialect.get())),
getSearchResultBuilder(() -> new SearchResultBuilder(!params.getNoContent(), params.getWithScores(), true)));
}

public final CommandObject<SearchResult> ftSearch(String indexName, Query query) {
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SEARCH), indexName)
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SEARCH, indexName)
.addParams(query.dialectOptional(searchDialect.get())), getSearchResultBuilder(() ->
new SearchResultBuilder(!query.getNoContent(), query.getWithScores(), true)));
}
Expand All @@ -3209,35 +3225,35 @@ public final CommandObject<SearchResult> ftSearch(byte[] indexName, Query query)
}

public final CommandObject<String> ftExplain(String indexName, Query query) {
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.EXPLAIN), indexName)
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.EXPLAIN, indexName)
.addParams(query.dialectOptional(searchDialect.get())), BuilderFactory.STRING);
}

public final CommandObject<List<String>> ftExplainCLI(String indexName, Query query) {
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.EXPLAINCLI), indexName)
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.EXPLAINCLI, indexName)
.addParams(query.dialectOptional(searchDialect.get())), BuilderFactory.STRING_LIST);
}

public final CommandObject<AggregationResult> ftAggregate(String indexName, AggregationBuilder aggr) {
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.AGGREGATE), indexName)
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.AGGREGATE, indexName)
.addParams(aggr.dialectOptional(searchDialect.get())), !aggr.isWithCursor() ? AggregationResult.SEARCH_AGGREGATION_RESULT
: AggregationResult.SEARCH_AGGREGATION_RESULT_WITH_CURSOR);
}

public final CommandObject<AggregationResult> 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),
AggregationResult.SEARCH_AGGREGATION_RESULT_WITH_CURSOR);
}

public final CommandObject<String> 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<Map.Entry<AggregationResult, Map<String, Object>>> 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)
.addParams(aggr.dialectOptional(searchDialect.get())), new SearchProfileResponseBuilder<>(
!aggr.isWithCursor() ? AggregationResult.SEARCH_AGGREGATION_RESULT
Expand All @@ -3246,15 +3262,15 @@ public final CommandObject<Map.Entry<AggregationResult, Map<String, Object>>> ft

public final CommandObject<Map.Entry<SearchResult, Map<String, Object>>> 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.dialectOptional(searchDialect.get())), new SearchProfileResponseBuilder<>(
getSearchResultBuilder(() -> new SearchResultBuilder(!query.getNoContent(), query.getWithScores(), true))));
}

public final CommandObject<Map.Entry<SearchResult, Map<String, Object>>> 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.dialectOptional(searchDialect.get())), new SearchProfileResponseBuilder<>(
getSearchResultBuilder(() -> new SearchResultBuilder(!searchParams.getNoContent(), searchParams.getWithScores(), true))));
Expand All @@ -3266,12 +3282,12 @@ private Builder<SearchResult> getSearchResultBuilder(Supplier<Builder<SearchResu
}

public final CommandObject<String> 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<Map<String, List<String>>> ftSynDump(String indexName) {
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SYNDUMP), indexName),
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SYNDUMP, indexName),
SearchBuilderFactory.SEARCH_SYNONYM_GROUPS);
}

Expand Down Expand Up @@ -3302,23 +3318,23 @@ public final CommandObject<Set<String>> ftDictDumpBySampleKey(String indexName,
}

public final CommandObject<Map<String, Map<String, Double>>> 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<Map<String, Map<String, Double>>> 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.dialectOptional(searchDialect.get())), SearchBuilderFactory.SEARCH_SPELLCHECK_RESPONSE);
}

public final CommandObject<Map<String, Object>> ftInfo(String indexName) {
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.INFO), indexName),
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.INFO, indexName),
protocol == RedisProtocol.RESP3 ? BuilderFactory.AGGRESSIVE_ENCODED_OBJECT_MAP : BuilderFactory.ENCODED_OBJECT_MAP);
}

public final CommandObject<Set<String>> 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);
}

Expand Down
Loading