Skip to content

Commit

Permalink
Address PR review.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
  • Loading branch information
Yury-Fridlyand committed Oct 25, 2024
1 parent 14ee140 commit 3bd976b
Showing 1 changed file with 11 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,20 @@
import glide.api.models.GlideString;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import lombok.NonNull;

/** Mandatory parameters for {@link FT#profile} command. */
public class FTProfileOptions {
private final QueryType queryType;
private final boolean limited;
private final GlideString[] query;
private final GlideString[] commandLine;

/** Query type being profiled. */
public enum QueryType {
enum QueryType {
SEARCH,
AGGREGATE
}

/**
* Profile a query given as an array of module command line arguments.
*
* @param queryType The query type.
* @param commandLine Command arguments (not including index name).
*/
public FTProfileOptions(@NonNull QueryType queryType, @NonNull GlideString[] commandLine) {
this(queryType, commandLine, false);
}

/**
* Profile a query given as an array of module command line arguments.
*
* @param queryType The query type.
* @param commandLine Command arguments (not including index name).
*/
public FTProfileOptions(@NonNull QueryType queryType, @NonNull String[] commandLine) {
this(queryType, commandLine, false);
}

/**
* Profile a query given as an array of module command line arguments.
*
* @param queryType The query type.
* @param commandLine Command arguments (not including index name).
* @param limited Either provide a full verbose output or some brief version (limited).
*/
public FTProfileOptions(
@NonNull QueryType queryType, @NonNull GlideString[] commandLine, boolean limited) {
this.queryType = queryType;
this.query = commandLine;
this.limited = limited;
}

/**
* Profile a query given as an array of module command line arguments.
*
* @param queryType The query type.
* @param commandLine Command arguments (not including index name).
* @param limited Either provide a full verbose output or some brief version (limited).
*/
public FTProfileOptions(
@NonNull QueryType queryType, @NonNull String[] commandLine, boolean limited) {
this(
queryType,
Stream.of(commandLine).map(GlideString::gs).toArray(GlideString[]::new),
limited);
}

/**
* Profile an aggregation query with given parameters.
*
Expand All @@ -89,7 +39,7 @@ public FTProfileOptions(@NonNull String query, @NonNull FTAggregateOptions optio
* @param options {@link FT#aggregate} options.
*/
public FTProfileOptions(@NonNull GlideString query, @NonNull FTAggregateOptions options) {
this(QueryType.AGGREGATE, concatenateArrays(new GlideString[] {query}, options.toArgs()));
this(query, options, false);
}

/**
Expand All @@ -109,7 +59,7 @@ public FTProfileOptions(@NonNull String query, @NonNull FTSearchOptions options)
* @param options {@link FT#search} options.
*/
public FTProfileOptions(@NonNull GlideString query, @NonNull FTSearchOptions options) {
this(QueryType.SEARCH, concatenateArrays(new GlideString[] {query}, options.toArgs()));
this(query, options, false);
}

/**
Expand All @@ -133,10 +83,9 @@ public FTProfileOptions(
*/
public FTProfileOptions(
@NonNull GlideString query, @NonNull FTAggregateOptions options, boolean limited) {
this(
QueryType.AGGREGATE,
concatenateArrays(new GlideString[] {query}, options.toArgs()),
limited);
queryType = QueryType.AGGREGATE;
commandLine = concatenateArrays(new GlideString[] {query}, options.toArgs());
this.limited = limited;
}

/**
Expand All @@ -160,7 +109,9 @@ public FTProfileOptions(
*/
public FTProfileOptions(
@NonNull GlideString query, @NonNull FTSearchOptions options, boolean limited) {
this(QueryType.SEARCH, concatenateArrays(new GlideString[] {query}, options.toArgs()), limited);
queryType = QueryType.AGGREGATE;
commandLine = concatenateArrays(new GlideString[] {query}, options.toArgs());
this.limited = limited;
}

/** Convert to module API. */
Expand All @@ -169,7 +120,7 @@ public GlideString[] toArgs() {
args.add(gs(queryType.toString()));
if (limited) args.add(gs("LIMITED"));
args.add(gs("QUERY"));
args.addAll(List.of(query));
args.addAll(List.of(commandLine));
return args.toArray(GlideString[]::new);
}
}

0 comments on commit 3bd976b

Please sign in to comment.