Python 2.7 has reached end of supportand will bedeprecatedon January 31, 2026. After deprecation, you won't be able to deploy Python 2.7applications, even if your organization previously used an organization policy tore-enable deployments of legacy runtimes. Your existing Python2.7 applications will continue to run and receive traffic after theirdeprecation date. We recommend thatyoumigrate to the latest supported version of Python.

The SortExpression Class

ClassSortExpression allows you to customize how your search results are sorted.

This API is supported for first-generation runtimes and can be used whenupgrading to corresponding second-generation runtimes. If you are updating to the App Engine Python 3 runtime, refer to themigration guide to learn about your migration options for legacy bundled services.

SortExpression is defined in thegoogle.appengine.api.search module.

Constructor

The constructor for classSortExpression is defined as follows:

class SortExpression(expression=None,direction=DESCENDING,default_value=None)

Sort results by the specified scoring expression.

Arguments

expression

An expression to be evaluated when sorting results for each matching document. The expression can simply be a field name, or some compound expression such as_score + count(likes) * 0.1which will add the score from a scorer to a count of the values of alikes field weighted by a factor of 0.1.

direction

The direction to sort the search results, either ASCENDING or DESCENDING.

default_value

The default value of the expression, if no field is present and cannot be calculated for a document. A text value must be specified for text sorts. A numeric value must be specified for numeric sorts.

Result value

A new instance of classSortExpression.

Exceptions

TypeError

If any of the parameters have an invalid type, or an unknown attribute is passed.

ValueError

If any parameter has an invalid value.

Properties

An instance of classSortExpression has the following properties:

expression

Returns the expression used to sort matched results.

direction

Returns the direction of sort expression:ASCENDING orDESCENDING.

default_value

Returns a default value for the expression if no other value could be computed.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.