Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
Signed-off-by: Chloe <chloe.yip@improving.com>
  • Loading branch information
cyip10 committed Oct 25, 2024
1 parent 704f21f commit 3b2700d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 133 deletions.
145 changes: 28 additions & 117 deletions java/client/src/main/java/glide/api/commands/servermodules/FT.java
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,13 @@ public static CompletableFuture<String> aliasupdate(
* @return A <code>string</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explain(client, "myIndex", "*=>[KNN 2 @VEC $query_vec]").get(); // "Vector"
* FT.explain(client, "myIndex", "@price:[0 10]").get();
* // the result can look like (the result is a string):
* // Field {
* // price
* // 0
* // 10
* // }
* }</pre>
*/
public static CompletableFuture<String> explain(
Expand All @@ -727,7 +733,13 @@ public static CompletableFuture<String> explain(
* @return A <code>string</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explain(client, gs("myIndex"), gs("*=>[KNN 2 @VEC $query_vec]")).get(); // "Vector"
* FT.explain(client, "myIndex", "@price:[0 10]").get();
* // the result can look like (the result is a string):
* // Field {
* // price
* // 0
* // 10
* // }
* }</pre>
*/
public static CompletableFuture<GlideString> explain(
Expand All @@ -736,59 +748,6 @@ public static CompletableFuture<GlideString> explain(
return executeCommand(client, args, false);
}

/**
* Parse a query and return information about how that query was parsed.
*
* @param client The client to execute the command.
* @param indexName The index name to search into.
* @param query The text query to search. It is the same as the query passed as an argument to
* {@link FT#search(BaseClient, String, String)}.
* @param dialect The dialect version under which to execute the query. If not specified, the
* query executes under the default dialect version set during module initial loading.
* @return A <code>string</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explain(client, "myIndex", "*=>[KNN 2 @VEC $query_vec]", 12.2).get(); // "Vector"
* }</pre>
*/
public static CompletableFuture<String> explain(
@NonNull BaseClient client,
@NonNull String indexName,
@NonNull String query,
@NonNull Double dialect) {
var args =
concatenateArrays(
new GlideString[] {gs("FT.EXPLAIN"), gs(indexName), gs(query), gs(dialect.toString())});
return executeCommand(client, args, false)
.thenApply(result -> ((GlideString) result).toString());
}

/**
* Parse a query and return information about how that query was parsed.
*
* @param client The client to execute the command.
* @param indexName The index name to search into.
* @param query The text query to search. It is the same as the query passed as an argument to
* {@link FT#search(BaseClient, String, String)}.
* @param dialect The dialect version under which to execute the query. If not specified, the
* query executes under the default dialect version set during module initial loading.
* @return A <code>string</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explain(client, gs("myIndex"), gs("*=>[KNN 2 @VEC $query_vec]"), 12.2).get(); // "Vector"
* }</pre>
*/
public static CompletableFuture<GlideString> explain(
@NonNull BaseClient client,
@NonNull GlideString indexName,
@NonNull GlideString query,
@NonNull Double dialect) {
var args =
concatenateArrays(
new GlideString[] {gs("FT.EXPLAIN"), indexName, query, gs(dialect.toString())});
return executeCommand(client, args, false);
}

/**
* Same as the {@link FT#explain(BaseClient, String, String)} except that the results are
* displayed in a different format. More useful with cli.
Expand All @@ -800,7 +759,13 @@ public static CompletableFuture<GlideString> explain(
* @return A <code>string array</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explaincli(client, "myIndex", "*=>[KNN 2 @VEC $query_vec]").get(); // "Vector"
* FT.explaincli(client, "myIndex", "@price:[0 10]").get();
* // the output can look like this (the result is an array)
* // Field {
* // price
* // 0
* // 10
* // }
* }</pre>
*/
public static CompletableFuture<String[]> explaincli(
Expand All @@ -821,7 +786,13 @@ public static CompletableFuture<String[]> explaincli(
* @return A <code>string array</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explaincli(client, gs("myIndex"), gs("*=>[KNN 2 @VEC $query_vec]")).get(); // "Vector"
* FT.explaincli(client, "myIndex", "@price:[0 10]").get();
* // the output can look like this (the result is an array)
* // Field {
* // price
* // 0
* // 10
* // }
* }</pre>
*/
public static CompletableFuture<GlideString[]> explaincli(
Expand All @@ -836,66 +807,6 @@ public static CompletableFuture<GlideString[]> explaincli(
return result;
}

/**
* Same as the {@link FT#explain(BaseClient, String, String)} except that the results are
* displayed in a different format. More useful with cli.
*
* @param client The client to execute the command.
* @param indexName The index name to search into.
* @param query The text query to search. It is the same as the query passed as an argument to
* {@link FT#search(BaseClient, String, String)}.
* @param dialect The dialect version under which to execute the query. If not specified, the
* query executes under the default dialect version set during module initial loading.
* @return A <code>string array</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explaincli(client, "myIndex", "*=>[KNN 2 @VEC $query_vec]", 12.2).get(); // "Vector"
* }</pre>
*/
public static CompletableFuture<String[]> explaincli(
@NonNull BaseClient client,
@NonNull String indexName,
@NonNull String query,
@NonNull Double dialect) {
CompletableFuture<GlideString[]> result = explaincli(client, gs(indexName), gs(query), dialect);
return result.thenApply(
ret -> Arrays.stream(ret).map(e -> e.getString()).toArray(String[]::new));
}

/**
* Same as the {@link FT#explain(BaseClient, String, String)} except that the results are
* displayed in a different format. More useful with cli.
*
* @param client The client to execute the command.
* @param indexName The index name to search into.
* @param query The text query to search. It is the same as the query passed as an argument to
* {@link FT#search(BaseClient, String, String)}.
* @param dialect The dialect version under which to execute the query. If not specified, the
* query executes under the default dialect version set during module initial loading.
* @param options The additional parameter for the command - see {@link FTCreateOptions}.
* @return A <code>string array</code> representing the execution plan.
* @example
* <pre>{@code
* FT.explaincli(client, gs("myIndex"), gs("*=>[KNN 2 @VEC $query_vec]"), 12.2).get(); // "Vector"
* }</pre>
*/
public static CompletableFuture<GlideString[]> explaincli(
@NonNull BaseClient client,
@NonNull GlideString indexName,
@NonNull GlideString query,
@NonNull Double dialect) {
var args =
concatenateArrays(
new GlideString[] {gs("FT.EXPLAINCLI"), indexName, query, gs(dialect.toString())});
CompletableFuture<GlideString[]> result =
((GlideClusterClient) client)
.customCommand(args)
.thenApply(ClusterValue::getSingleValue)
.thenApply(ret -> (Object[]) ret)
.thenApply(ret -> castArray(ret, GlideString.class));
return result;
}

/**
* A wrapper for custom command API.
*
Expand Down
16 changes: 0 additions & 16 deletions java/integTest/src/test/java/glide/modules/VectorSearchTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,6 @@ public void ft_explain() {
result = resultGS.toString();
assertTrue(result.contains("*"));

// with dialect option
result = FT.explain(client, indexName, query, 1.2).get();
assertTrue(result.contains("price"));
assertTrue(result.contains("0"));
assertTrue(result.contains("10"));

assertEquals(OK, FT.dropindex(client, indexName).get());

// missing index throws an error.
Expand Down Expand Up @@ -908,16 +902,6 @@ public void ft_explaincli() {
}
assertTrue((resultListGS).contains("*"));

// with dialect option
resultList.clear();
result = FT.explaincli(client, indexName, query, 1.2).get();
for (String r : result) {
resultList.add(r.trim()); // trim to remove any excess white space
}
assertTrue(resultList.contains("price"));
assertTrue(resultList.contains("0"));
assertTrue(resultList.contains("10"));

assertEquals(OK, FT.dropindex(client, indexName).get());

// missing index throws an error.
Expand Down

0 comments on commit 3b2700d

Please sign in to comment.