Package com.redis.vl.query
Class SortSpec
java.lang.Object
com.redis.vl.query.SortSpec
Utility class for parsing flexible sort specifications into normalized format.
Python port: Corresponds to SortSpec type alias and _parse_sort_spec() static method in Python redisvl (PR #393)
Python SortSpec accepts:
- str: field name (defaults to ASC)
- Tuple[str, str]: (field_name, direction)
- List[Union[str, Tuple[str, str]]]: multiple fields with optional directions
Java SortSpec provides overloaded methods:
parseSortSpec(String field)- single field, ASCparseSortSpec(String field, String direction)- single field with directionparseSortSpec(SortField field)- single SortFieldparseSortSpec(List<SortField> fields)- multiple fields
Note: Redis Search only supports single-field sorting. When multiple fields are provided, only the first field is used and a warning is logged.
-
Method Summary
Modifier and TypeMethodDescriptionparseSortSpec(SortField field) Parse a single SortField.parseSortSpec(String field) Parse a single field name (defaults to ascending order).parseSortSpec(String field, String direction) Parse a single field name with direction.parseSortSpec(List<SortField> fields) Parse a list of SortFields (supports multiple fields).
-
Method Details
-
parseSortSpec
Parse a single field name (defaults to ascending order).Python equivalent: sort_by="price"
- Parameters:
field- Field name to sort by- Returns:
- List containing single SortField with ascending=true
- Throws:
IllegalArgumentException- if field is null or empty
-
parseSortSpec
Parse a single field name with direction.Python equivalent: sort_by=("price", "DESC")
- Parameters:
field- Field name to sort bydirection- Sort direction ("ASC" or "DESC", case-insensitive)- Returns:
- List containing single SortField
- Throws:
IllegalArgumentException- if field is null/empty or direction is invalid
-
parseSortSpec
Parse a single SortField.- Parameters:
field- SortField to wrap in list- Returns:
- List containing the single SortField
- Throws:
IllegalArgumentException- if field is null
-
parseSortSpec
Parse a list of SortFields (supports multiple fields).Python equivalent: sort_by=[("price", "DESC"), ("rating", "ASC"), "stock"]
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:
fields- List of SortFields- Returns:
- List of SortFields (may be empty, uses only first field for Redis)
-