Configures the sort field and sort direction for document ranking in OpenSearch search queries.
Constructor
SortField(String field, Order order)| Parameter | Type | Description |
|---|---|---|
field | String | The field to sort by. |
order | Order (enumeration type) | The sort direction. Valid values: Order.INCREASE (ascending, lowest to highest) and Order.DECREASE (descending, highest to lowest). |
Example
// Sort by "price" in ascending order
SortField sortByPrice = new SortField("price", Order.INCREASE); // ①
// Sort by "score" in descending order
SortField sortByScore = new SortField("score", Order.DECREASE); // ②① Order.INCREASE sorts results from the lowest to the highest value. ② Order.DECREASE sorts results from the highest to the lowest value.
Methods
setField
SortField setField(String field)Sets the field to sort by. Returns the SortField instance.
| Parameter | Type | Description |
|---|---|---|
field | String | The field to sort by. |
getField
String getField()Returns the field currently set for sorting.
| Return value | Type | Description |
|---|---|---|
| Field name | String | The field set for sorting. |
setOrder
SortField setOrder(Order order)Sets the sort direction. Returns the SortField instance.
| Parameter | Type | Description |
|---|---|---|
order | Order (enumeration type) | The sort direction. Valid values: Order.INCREASE (ascending, lowest to highest) and Order.DECREASE (descending, highest to lowest). |
getOrder
Order getOrder()Returns the sort direction currently set.
| Return value | Type | Description |
|---|---|---|
| Sort direction | Order | The sort direction. Valid values: Order.INCREASE (ascending) and Order.DECREASE (descending). |
What's next
For the full list of Order enum values, see Order.
该文章对您有帮助吗?