SortField class

更新时间:
复制 MD 格式

Configures the sort field and sort direction for document ranking in OpenSearch search queries.

Constructor

SortField(String field, Order order)
ParameterTypeDescription
fieldStringThe field to sort by.
orderOrder (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.

ParameterTypeDescription
fieldStringThe field to sort by.

getField

String getField()

Returns the field currently set for sorting.

Return valueTypeDescription
Field nameStringThe field set for sorting.

setOrder

SortField setOrder(Order order)

Sets the sort direction. Returns the SortField instance.

ParameterTypeDescription
orderOrder (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 valueTypeDescription
Sort directionOrderThe sort direction. Valid values: Order.INCREASE (ascending) and Order.DECREASE (descending).

What's next

For the full list of Order enum values, see Order.