RediSearchCommands.java

package redis.clients.jedis.search;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.annots.Experimental;
import redis.clients.jedis.commands.ConfigCommands;
import redis.clients.jedis.resps.Tuple;
import redis.clients.jedis.search.aggr.AggregateIterator;
import redis.clients.jedis.search.aggr.AggregationBuilder;
import redis.clients.jedis.search.aggr.AggregationResult;
import redis.clients.jedis.search.hybrid.FTHybridParams;
import redis.clients.jedis.search.hybrid.HybridResult;
import redis.clients.jedis.search.schemafields.SchemaField;

public interface RediSearchCommands {

  String ftCreate(String indexName, IndexOptions indexOptions, Schema schema);

  default String ftCreate(String indexName, SchemaField... schemaFields) {
    return ftCreate(indexName, Arrays.asList(schemaFields));
  }

  default String ftCreate(String indexName, FTCreateParams createParams, SchemaField... schemaFields) {
    return ftCreate(indexName, createParams, Arrays.asList(schemaFields));
  }

  default String ftCreate(String indexName, Iterable<SchemaField> schemaFields) {
    return ftCreate(indexName, FTCreateParams.createParams(), schemaFields);
  }

  String ftCreate(String indexName, FTCreateParams createParams, Iterable<SchemaField> schemaFields);

  default String ftAlter(String indexName, Schema.Field... fields) {
    return ftAlter(indexName, Schema.from(fields));
  }

  String ftAlter(String indexName, Schema schema);

  default String ftAlter(String indexName, SchemaField... schemaFields) {
    return ftAlter(indexName, Arrays.asList(schemaFields));
  }

  String ftAlter(String indexName, Iterable<SchemaField> schemaFields);

  String ftAliasAdd(String aliasName, String indexName);

  String ftAliasUpdate(String aliasName, String indexName);

  String ftAliasDel(String aliasName);

  String ftDropIndex(String indexName);

  String ftDropIndexDD(String indexName);

  default SearchResult ftSearch(String indexName) {
    return ftSearch(indexName, "*");
  }

  SearchResult ftSearch(String indexName, String query);

  SearchResult ftSearch(String indexName, String query, FTSearchParams params);

  SearchResult ftSearch(String indexName, Query query);

  @Deprecated
  SearchResult ftSearch(byte[] indexName, Query query);

  String ftExplain(String indexName, Query query);

  List<String> ftExplainCLI(String indexName, Query query);

  /**
   * Execute an aggregation query and return all results at once.
   * Use this method when you don't need cursor-based pagination and want to retrieve
   * all results in a single operation.
   * @param indexName the index name
   * @param aggr the aggregation builder containing the query
   * @return the complete aggregation result
   */
  AggregationResult ftAggregate(String indexName, AggregationBuilder aggr);

  /**
   * Execute an aggregation query with cursor-based iteration support.
   * Use this method when you need to paginate through large result sets or want
   * to process results incrementally using cursor-based iteration.
   * @param indexName the index name
   * @param aggr the aggregation builder containing the query (should include cursor configuration)
   * @return an iterator for cursor-based result pagination
   */
  AggregateIterator ftAggregateIterator(String indexName, AggregationBuilder aggr);

  /**
   * Read from an aggregation cursor.
   * @param indexName the index name
   * @param cursorId the cursor ID
   * @param count the number of results to read
   * @return the aggregation result
   * @deprecated Use {@link #ftAggregate(String, AggregationBuilder)} for operations without cursors,
   *             or {@link #ftAggregateIterator(String, AggregationBuilder)} for cursor-based iteration
   */
  @Deprecated
  AggregationResult ftCursorRead(String indexName, long cursorId, int count);

  /**
   * Delete an aggregation cursor.
   * @param indexName the index name
   * @param cursorId the cursor ID
   * @return the result of the cursor deletion
   * @deprecated Use {@link #ftAggregate(String, AggregationBuilder)} for operations without cursors,
   *             or {@link #ftAggregateIterator(String, AggregationBuilder)} for cursor-based iteration
   */
  @Deprecated
  String ftCursorDel(String indexName, long cursorId);

  Map.Entry<AggregationResult, ProfilingInfo> ftProfileAggregate(String indexName,
      FTProfileParams profileParams, AggregationBuilder aggr);

  Map.Entry<SearchResult, ProfilingInfo> ftProfileSearch(String indexName,
      FTProfileParams profileParams, Query query);

  Map.Entry<SearchResult, ProfilingInfo> ftProfileSearch(String indexName,
      FTProfileParams profileParams, String query, FTSearchParams searchParams);

  String ftSynUpdate(String indexName, String synonymGroupId, String... terms);

  Map<String, List<String>> ftSynDump(String indexName);

  long ftDictAdd(String dictionary, String... terms);

  long ftDictDel(String dictionary, String... terms);

  Set<String> ftDictDump(String dictionary);

  long ftDictAddBySampleKey(String indexName, String dictionary, String... terms);

  long ftDictDelBySampleKey(String indexName, String dictionary, String... terms);

  Set<String> ftDictDumpBySampleKey(String indexName, String dictionary);

  Map<String, Map<String, Double>> ftSpellCheck(String index, String query);

  Map<String, Map<String, Double>> ftSpellCheck(String index, String query,
      FTSpellCheckParams spellCheckParams);

  Map<String, Object> ftInfo(String indexName);

  Set<String> ftTagVals(String indexName, String fieldName);

  /**
   * @deprecated {@link ConfigCommands#configGet(java.lang.String)} is used since Redis 8.
   */
  @Deprecated
  Map<String, Object> ftConfigGet(String option);

  @Deprecated
  Map<String, Object> ftConfigGet(String indexName, String option);

  /**
   * @deprecated {@link ConfigCommands#configSet(java.lang.String, java.lang.String)} is used since Redis 8.
   */
  @Deprecated
  String ftConfigSet(String option, String value);

  @Deprecated
  String ftConfigSet(String indexName, String option, String value);

  long ftSugAdd(String key, String string, double score);

  long ftSugAddIncr(String key, String string, double score);

  List<String> ftSugGet(String key, String prefix);

  List<String> ftSugGet(String key, String prefix, boolean fuzzy, int max);

  List<Tuple> ftSugGetWithScores(String key, String prefix);

  List<Tuple> ftSugGetWithScores(String key, String prefix, boolean fuzzy, int max);

  boolean ftSugDel(String key, String string);

  long ftSugLen(String key);

  Set<String> ftList();

  /**
   * Execute a hybrid query combining text search and vector similarity.
   *
   * @param indexName the index name
   * @param hybridParams the hybrid query arguments
   * @return the hybrid search results
   * @see FTHybridParams
   * @see HybridResult
   */
  @Experimental
  HybridResult ftHybrid(String indexName, FTHybridParams hybridParams);
}