com.google.appengine.api.search
Class SortExpression.Builder
- java.lang.Object
-
- com.google.appengine.api.search.SortExpression.Builder
-
- Enclosing class:
- SortExpression
public static final class SortExpression.Builder extends java.lang.Object
A builder that constructsSortExpressions
. 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()
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description SortExpression
build()
Builds aSortExpression
from the set values.SortExpression.Builder
setDefaultValue(java.lang.String defaultValue)
Sets the default value for the field for sorting purposes.SortExpression.Builder
setDefaultValueDate(java.util.Date defaultValue)
Sets the default value for the field for sorting purposes.SortExpression.Builder
setDefaultValueNumeric(double defaultValue)
Sets the default value for the field for sorting purposes.SortExpression.Builder
setDirection(SortExpression.SortDirection direction)
Sets the direction to sort the search results in.SortExpression.Builder
setExpression(java.lang.String expression)
Sets an expression to be evaluated for each document to sort by.
-
-
-
Method Detail
-
setExpression
public SortExpression.Builder setExpression(java.lang.String expression)
Sets an expression to be evaluated for each document to sort by. A default string valuesetDefaultValue(String)
or numericsetDefaultValueNumeric(double)
or datesetDefaultValueDate(Date)
must be specified for the expression.- Parameters:
expression
- the expression to evaluate for each document to sort by- Returns:
- this Builder
- Throws:
java.lang.IllegalArgumentException
- if the expression is invalid
-
setDirection
public SortExpression.Builder setDirection(SortExpression.SortDirection direction)
Sets the direction to sort the search results in.- Parameters:
direction
- the direction to sort the search results in. The default direction isSortExpression.SortDirection.DESCENDING
- Returns:
- this Builder
-
setDefaultValue
public SortExpression.Builder setDefaultValue(java.lang.String defaultValue)
Sets the default value for the field for sorting purposes. Must provide for text sorts.- Parameters:
defaultValue
- the default value for the field- Returns:
- this Builder
- Throws:
java.lang.IllegalArgumentException
- if thedefaultValue
is not valid
-
setDefaultValueNumeric
public SortExpression.Builder setDefaultValueNumeric(double defaultValue)
Sets the default value for the field for sorting purposes. Must provide for numeric sorts.- Parameters:
defaultValue
- the default value for the field- Returns:
- this Builder
-
setDefaultValueDate
public SortExpression.Builder setDefaultValueDate(java.util.Date defaultValue)
Sets the default value for the field for sorting purposes. Must provide for Date sorts. Typically, you should useSearchApiLimits.MINIMUM_DATE_VALUE
orSearchApiLimits.MAXIMUM_DATE_VALUE
as a default value.- Parameters:
defaultValue
- the default value for the field- Returns:
- this Builder
-
build
public SortExpression build()
Builds aSortExpression
from the set values.- Returns:
- a
SortExpression
built from the set values - Throws:
java.lang.IllegalArgumentException
- if the field name or default value is invalid
-
-