Package com.redis.vl.query
Class TextQuery.Builder
java.lang.Object
com.redis.vl.query.TextQuery.Builder
- Enclosing class:
TextQuery
Builder for TextQuery with support for field weights and sorting.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the TextQuery instance.filterExpression(Filter filterExpression) Set the filter expression.numResults(int numResults) Set the number of results to return.Set the scoring algorithm.skipDecodeFields(String... fields) Set fields that should not be decoded from binary format (varargs).skipDecodeFields(List<String> skipDecodeFields) Set fields that should not be decoded from binary format.Set the sort field using SortField.Set the sort field (defaults to ascending).Set the sort field with explicit direction.Set the sort fields (supports multiple fields, but only first is used).sortDescending(boolean descending) Set whether to sort in descending order.Set the text to search for.Set a single text field to search (backward compatible).textFieldWeights(Map<String, Double> fieldWeights) Set multiple text fields with weights.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
text
Set the text to search for.- Parameters:
text- Search text- Returns:
- Builder
-
textField
Set a single text field to search (backward compatible).- Parameters:
fieldName- Field name- Returns:
- Builder
-
textFieldWeights
Set multiple text fields with weights.- Parameters:
fieldWeights- Map of field names to weights- Returns:
- Builder
-
scorer
Set the scoring algorithm.- Parameters:
scorer- Scorer name (e.g., BM25STD, TFIDF)- Returns:
- Builder
-
filterExpression
Set the filter expression.- Parameters:
filterExpression- Filter to apply- Returns:
- Builder
-
numResults
Set the number of results to return.- Parameters:
numResults- Number of results- Returns:
- Builder
-
sortBy
Set the sort field (defaults to ascending).Python equivalent: sort_by="price"
- Parameters:
sortBy- Field name to sort by- Returns:
- This builder
-
sortBy
Set the sort field with explicit direction.Python equivalent: sort_by=("price", "DESC")
- Parameters:
field- Field name to sort bydirection- Sort direction ("ASC" or "DESC", case-insensitive)- Returns:
- This builder
- Throws:
IllegalArgumentException- if direction is invalid
-
sortBy
Set the sort field using SortField.Python equivalent: sort_by=("rating", "DESC") or using SortField.desc("rating")
- Parameters:
sortField- SortField specifying field and direction- Returns:
- This builder
- Throws:
IllegalArgumentException- if sortField is null
-
sortBy
Set the sort fields (supports multiple fields, but only first is used).Python equivalent: sort_by=[("price", "ASC"), ("rating", "DESC")]
Note: Redis Search only supports single-field sorting. When multiple fields are provided, only the first field is used and a warning is logged.
- Parameters:
sortFields- List of SortFields- Returns:
- This builder
-
sortDescending
Set whether to sort in descending order.- Parameters:
descending- True for descending sort- Returns:
- This builder
-
skipDecodeFields
Set fields that should not be decoded from binary format.- Parameters:
skipDecodeFields- List of field names- Returns:
- This builder
- Throws:
IllegalArgumentException- if list contains null values
-
skipDecodeFields
Set fields that should not be decoded from binary format (varargs).- Parameters:
fields- Field names- Returns:
- This builder
- Throws:
IllegalArgumentException- if any field is null
-
build
Build the TextQuery instance.- Returns:
- TextQuery
- Throws:
IllegalArgumentException- if text is null or field weights are empty
-