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 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()

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `SortExpression` | `build()` Builds a `SortExpression` 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.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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 value `setDefaultValue(String)` or numeric `setDefaultValueNumeric(double)` or date `setDefaultValueDate(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 is `SortExpression.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 the `defaultValue` 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 use `SearchApiLimits.MINIMUM_DATE_VALUE` or `SearchApiLimits.MAXIMUM_DATE_VALUE` as a default value.
      Parameters:
        `defaultValue` - the default value for the field
      Returns:
        this Builder

    - #### build

          public SortExpression build()

      Builds a `SortExpression` 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