Class TextQuery

java.lang.Object
com.redis.vl.query.TextQuery

public class TextQuery extends Object
Full-text search query with support for field weights and sorting.

Python port: Implements text_field_name with Union[str, Dict[str, float]] for weighted text search across multiple fields.

Example usage:


 // Single field (backward compatible)
 TextQuery query = TextQuery.builder()
     .text("search terms")
     .textField("description")
     .build();

 // Multiple fields with weights
 TextQuery query = TextQuery.builder()
     .text("search terms")
     .textFieldWeights(Map.of("title", 5.0, "content", 2.0, "tags", 1.0))
     .build();

 // With sorting
 TextQuery query = TextQuery.builder()
     .text("search terms")
     .textField("description")
     .sortBy("price", "DESC")
     .build();
 
  • Method Details

    • setFieldWeights

      public void setFieldWeights(Map<String,Double> fieldWeights)
      Update the field weights dynamically.
      Parameters:
      fieldWeights - Map of field names to weights
    • getFieldWeights

      public Map<String,Double> getFieldWeights()
      Get a copy of the field weights.
      Returns:
      Map of field names to weights
    • getSkipDecodeFields

      public List<String> getSkipDecodeFields()
      Get the list of fields that should not be decoded from binary format.
      Returns:
      List of field names to skip decoding
    • toQueryString

      public String toQueryString()
      Build the Redis query string for text search with weighted fields.

      Format:

      • Single field default weight: @field:(term1 | term2)
      • Single field with weight: @field:(term1 | term2) => { $weight: 5.0 }
      • Multiple fields: (@field1:(terms) => { $weight: 3.0 } | @field2:(terms) => { $weight: 2.0 })
      Returns:
      Redis query string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static TextQuery.Builder builder()
      Create a new Builder for TextQuery.
      Returns:
      Builder instance