The expression to be used if you wish to sort by language
code associated with the locale field Document#getLocale().
You need to create a sort expression as
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
a new 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
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003e\u003ccode\u003eSortExpression\u003c/code\u003e is a class used to specify sorting criteria for a single dimension, with support for multi-dimensional sorting through a collection of \u003ccode\u003eSortExpressions\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe class offers static fields like \u003ccode\u003eDOCUMENT_ID_FIELD_NAME\u003c/code\u003e, \u003ccode\u003eLANGUAGE_FIELD_NAME\u003c/code\u003e, \u003ccode\u003eRANK_FIELD_NAME\u003c/code\u003e, \u003ccode\u003eSCORE_FIELD_NAME\u003c/code\u003e, and \u003ccode\u003eTIMESTAMP_FIELD_NAME\u003c/code\u003e to facilitate sorting by document ID, language code, rank, score, or timestamp respectively, and each require use of the builder pattern.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003enewBuilder()\u003c/code\u003e static method creates a \u003ccode\u003eSortExpression.Builder\u003c/code\u003e to define the sort specification parameters, allowing for the creation of a \u003ccode\u003eSortExpression\u003c/code\u003e instance.\u003c/p\u003e\n"],["\u003cp\u003eMethods such as \u003ccode\u003egetDefaultValue()\u003c/code\u003e, \u003ccode\u003egetDefaultValueDate()\u003c/code\u003e, \u003ccode\u003egetDefaultValueNumeric()\u003c/code\u003e, \u003ccode\u003egetDirection()\u003c/code\u003e, and \u003ccode\u003egetExpression()\u003c/code\u003e are provided to retrieve sorting details, such as default values, direction and the sorting expression itself.\u003c/p\u003e\n"],["\u003cp\u003eThis class inherits from the \u003ccode\u003ejava.lang.Object\u003c/code\u003e class and consequently inherits methods such as \u003ccode\u003eclone()\u003c/code\u003e, \u003ccode\u003eequals(Object)\u003c/code\u003e, and \u003ccode\u003etoString()\u003c/code\u003e, among others.\u003c/p\u003e\n"]]],[],null,["# Class SortExpression (2.0.0)\n\n public final class SortExpression\n\nSorting specification for a single dimension. Multi-dimensional sorting\nis supported by a collection of SortExpressions. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e SortExpression \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Fields\n-------------\n\n### DOCUMENT_ID_FIELD_NAME\n\n public static final String DOCUMENT_ID_FIELD_NAME\n\nThe expression to be used if you wish to sort by document id field\n[Document#getId()](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Document#com_google_appengine_api_search_Document_getId__).\nYou need to create a sort expression as \n\n\n SortExpression expr = SortExpression.newBuilder()\n .setExpression(SortExpression.DOCUMENT_ID_FIELD_NAME)\n .setDefaultValue(\"\")\n .build();\n \n### LANGUAGE_FIELD_NAME\n\n public static final String LANGUAGE_FIELD_NAME\n\nThe expression to be used if you wish to sort by language\ncode associated with the locale field [Document#getLocale()](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Document#com_google_appengine_api_search_Document_getLocale__).\nYou need to create a sort expression as \n\n\n SortExpression expr = SortExpression.newBuilder()\n .setExpression(SortExpression.LANGUAGE_FIELD_NAME)\n .setDefaultValue(\"\")\n .build();\n \n### RANK_FIELD_NAME\n\n public static final String RANK_FIELD_NAME\n\nThe expression to be used if you wish to sort by rank field.\nBy default, results are sorted in descending value of rank.\nTo sort in ascending order, you need to create a sort expression as \n\n\n SortExpression expr = SortExpression.newBuilder()\n .setExpression(SortExpression.RANK_FIELD_NAME)\n .setDirection(SortExpression.SortDirection.ASCENDING)\n .setDefaultValueNumeric(0)\n .build();\n \n### SCORE_FIELD_NAME\n\n public static final String SCORE_FIELD_NAME\n\nThe expression to be used if you wish to sort by document score.\nYou need to create a sort expression as \n\n\n SortExpression expr = SortExpression.newBuilder()\n .setExpression(String.format(\n \"%s + rating * 0.01\", SortExpression.SCORE_FIELD_NAME))\n .setDirection(SortExpression.SortDirection.DESCENDING)\n .setDefaultValueNumeric(0)\n .build();\n \n### TIMESTAMP_FIELD_NAME\n\n public static final String TIMESTAMP_FIELD_NAME\n\nThe expression to be used if you wish to sort by\nseconds since EPOCH that the document was written.\nYou need to create a sort expression as \n\n\n SortExpression expr = SortExpression.newBuilder()\n .setExpression(SortExpression.TIMESTAMP_FIELD_NAME)\n .setDefaultValueNumeric(0)\n .build();\n \nStatic Methods\n--------------\n\n### newBuilder()\n\n public static SortExpression.Builder newBuilder()\n\nCreates and returns a SortExpression Builder.\n\nMethods\n-------\n\n### getDefaultValue()\n\n public String getDefaultValue()\n\n### getDefaultValueDate()\n\n public Date getDefaultValueDate()\n\n### getDefaultValueNumeric()\n\n public Double getDefaultValueNumeric()\n\n### getDirection()\n\n public SortExpression.SortDirection getDirection()\n\n### getExpression()\n\n public String getExpression()\n\n### toString()\n\n public String toString()\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)"]]