Class SortExpression.Builder (2.0.0)

public static final class SortExpression.Builder

A builder that constructs SortExpressions. The user must provide an expression. The expression can be as simple as a field name, or can be some other expression such as "score + count(likes) * 0.1", which combines a scorer score with a count of the number of likes values times 0.1. A default value must be specified for the expression.


   SortExpression expr = SortExpression.newBuilder()
       .setExpression(String.format(
           "%s + count(likes) * 0.1", SortExpression.SCORE_FIELD_NAME))
       .setDirection(SortExpression.SortDirection.ASCENDING)
       .setDefaultValueNumeric(0.0)
       .build()
 

Inheritance

java.lang.Object > SortExpression.Builder

Methods

build()

public SortExpression build()

Builds a SortExpression from the set values.

Returns
TypeDescription
SortExpression

a SortExpression built from the set values

setDefaultValue(String defaultValue)

public SortExpression.Builder setDefaultValue(String defaultValue)

Sets the default value for the field for sorting purposes. Must provide for text sorts.

Parameter
NameDescription
defaultValueString

the default value for the field

Returns
TypeDescription
SortExpression.Builder

this Builder

setDefaultValueDate(Date defaultValue)

public SortExpression.Builder setDefaultValueDate(Date defaultValue)

Sets the default value for the field for sorting purposes. Must provide for Date sorts. Typically, you should use com.google.appengine.api.search.checkers.SearchApiLimits#MINIMUM_DATE_VALUE or com.google.appengine.api.search.checkers.SearchApiLimits#MAXIMUM_DATE_VALUE as a default value.

Parameter
NameDescription
defaultValueDate

the default value for the field

Returns
TypeDescription
SortExpression.Builder

this Builder

setDefaultValueNumeric(double defaultValue)

public SortExpression.Builder setDefaultValueNumeric(double defaultValue)

Sets the default value for the field for sorting purposes. Must provide for numeric sorts.

Parameter
NameDescription
defaultValuedouble

the default value for the field

Returns
TypeDescription
SortExpression.Builder

this Builder

setDirection(SortExpression.SortDirection direction)

public SortExpression.Builder setDirection(SortExpression.SortDirection direction)

Sets the direction to sort the search results in.

Parameter
NameDescription
directionSortExpression.SortDirection

the direction to sort the search results in. The default direction is SortDirection#DESCENDING

Returns
TypeDescription
SortExpression.Builder

this Builder

setExpression(String expression)

public SortExpression.Builder setExpression(String expression)

Sets an expression to be evaluated for each document to sort by. A default string value #setDefaultValue(String) or numeric #setDefaultValueNumeric(double) or date #setDefaultValueDate(Date) must be specified for the expression.

Parameter
NameDescription
expressionString

the expression to evaluate for each document to sort by

Returns
TypeDescription
SortExpression.Builder

this Builder