    public final class SortExpression

Sorting specification for a single dimension. Multi-dimensional sorting
is supported by a collection of SortExpressions.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> SortExpression

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Fields

### DOCUMENT_ID_FIELD_NAME

    public static final String DOCUMENT_ID_FIELD_NAME

The expression to be used if you wish to sort by document id field
[Document#getId()](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Document#com_google_appengine_api_search_Document_getId__).
You need to create a sort expression as


     SortExpression expr = SortExpression.newBuilder()
         .setExpression(SortExpression.DOCUMENT_ID_FIELD_NAME)
         .setDefaultValue("")
         .build();
     
| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### LANGUAGE_FIELD_NAME

    public static final String LANGUAGE_FIELD_NAME

The expression to be used if you wish to sort by language
code associated with the locale field [Document#getLocale()](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Document#com_google_appengine_api_search_Document_getLocale__).
You need to create a sort expression as


     SortExpression expr = SortExpression.newBuilder()
         .setExpression(SortExpression.LANGUAGE_FIELD_NAME)
         .setDefaultValue("")
         .build();
     
| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### RANK_FIELD_NAME

    public static final String RANK_FIELD_NAME

The expression to be used if you wish to sort by rank field.
By default, results are sorted in descending value of rank.
To sort in ascending order, you need to create a sort expression as


     SortExpression expr = SortExpression.newBuilder()
         .setExpression(SortExpression.RANK_FIELD_NAME)
         .setDirection(SortExpression.SortDirection.ASCENDING)
         .setDefaultValueNumeric(0)
         .build();
     
| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SCORE_FIELD_NAME

    public static final String SCORE_FIELD_NAME

The expression to be used if you wish to sort by document score.
You need to create a sort expression as


     SortExpression expr = SortExpression.newBuilder()
         .setExpression(String.format(
             "%s + rating * 0.01", SortExpression.SCORE_FIELD_NAME))
         .setDirection(SortExpression.SortDirection.DESCENDING)
         .setDefaultValueNumeric(0)
         .build();
     
| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### TIMESTAMP_FIELD_NAME

    public static final String TIMESTAMP_FIELD_NAME

The expression to be used if you wish to sort by
seconds since EPOCH that the document was written.
You need to create a sort expression as


     SortExpression expr = SortExpression.newBuilder()
         .setExpression(SortExpression.TIMESTAMP_FIELD_NAME)
         .setDefaultValueNumeric(0)
         .build();
     
| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

## Static Methods

### newBuilder()

    public static SortExpression.Builder newBuilder()

Creates and returns a SortExpression Builder.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.SortExpression.Builder` | a new [SortExpression.Builder](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.SortExpression.Builder). Set the parameters for the sort specification on the Builder, and use the Builder#build() method to create a concrete instance of SortExpression |

## Methods

### getDefaultValue()

    public String getDefaultValue()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | the default value for the field. Can be null |

### getDefaultValueDate()

    public Date getDefaultValueDate()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Date.html` | the default date value for the field. Can be null |

### getDefaultValueNumeric()

    public Double getDefaultValueNumeric()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html` | the default numeric value for the field. Can be null |

### getDirection()

    public SortExpression.SortDirection getDirection()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.SortExpression.SortDirection` | the direction to sort the search results in |

### getExpression()

    public String getExpression()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | the expression to evaluate for each document and sort by |

### toString()

    public String toString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)