Package com.redis.vl.query
Class TextQuery
java.lang.Object
com.redis.vl.query.TextQuery
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();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for TextQuery with support for field weights and sorting. -
Method Summary
Modifier and TypeMethodDescriptionstatic TextQuery.Builderbuilder()Create a new Builder for TextQuery.Get a copy of the field weights.Get the list of fields that should not be decoded from binary format.voidsetFieldWeights(Map<String, Double> fieldWeights) Update the field weights dynamically.Build the Redis query string for text search with weighted fields.toString()
-
Method Details
-
setFieldWeights
Update the field weights dynamically.- Parameters:
fieldWeights- Map of field names to weights
-
getFieldWeights
Get a copy of the field weights.- Returns:
- Map of field names to weights
-
getSkipDecodeFields
Get the list of fields that should not be decoded from binary format.- Returns:
- List of field names to skip decoding
-
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
- Single field default weight:
-
toString
-
builder
Create a new Builder for TextQuery.- Returns:
- Builder instance
-