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
Type Description
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
Name Description
defaultValue String

the default value for the field

Returns
Type Description
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
Name Description
defaultValue Date

the default value for the field

Returns
Type Description
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
Name Description
defaultValue double

the default value for the field

Returns
Type Description
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
Name Description
direction SortExpression.SortDirection

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

Returns
Type Description
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
Name Description
expression String

the expression to evaluate for each document to sort by

Returns
Type Description
SortExpression.Builder

this Builder