Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
SortExpression クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
SortExpression
クラスを使用すると、検索結果の並べ替え方法をカスタマイズできます。
SortExpression
は、google.appengine.api.search
モジュールで定義されます。
コンストラクタ
SortExpression
クラスのコンストラクタは、次のように定義されます。
- class SortExpression(expression=None, direction=DESCENDING, default_value=None)
指定したスコアリング式で結果を並べ替えます。
引数
- expression
一致するドキュメントごとに結果を並べ替える際に評価される式。この式は、単なるフィールド名の場合もあれば、複合式の場合もあります。たとえば、_score + count(likes) * 0.1
という複合式では、スコアラーからのスコアを、因数 0.1 で加重された likes
フィールドの値の数に加算します。
- direction
検索結果の並べ替えの方向。昇順(ASCENDING)または降順(DESCENDING)のいずれかになります。
- default_value
フィールドが存在せず、ドキュメントに関する計算ができない場合の、式のデフォルト値。テキストの並べ替えの場合、テキスト値を指定する必要があります。数字の並べ替えの場合は、数値を指定してください。
結果値
SortExpression
クラスの新しいインスタンス。
例外
- TypeError
いずれかのパラメータが無効なタイプであるか、不明な属性が渡されました。
- ValueError
いずれかのパラメータの値が無効です。
プロパティ
SortExpression
クラスのインスタンスには次のプロパティがあります。
- expression
一致した結果の並べ替えに使用される式を返します。
- direction
並べ替えの式の方向(ASCENDING
または DESCENDING
)を返します。
- default_value
他の値が計算できない場合の式のデフォルト値を返します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[[["\u003cp\u003eThe \u003ccode\u003eSortExpression\u003c/code\u003e class enables customization of search result sorting using an expression.\u003c/p\u003e\n"],["\u003cp\u003eIt can be used with first-generation runtimes and is applicable when upgrading to second-generation runtimes.\u003c/p\u003e\n"],["\u003cp\u003eThe class constructor accepts \u003ccode\u003eexpression\u003c/code\u003e, \u003ccode\u003edirection\u003c/code\u003e (\u003ccode\u003eASCENDING\u003c/code\u003e or \u003ccode\u003eDESCENDING\u003c/code\u003e), and \u003ccode\u003edefault_value\u003c/code\u003e to define how results are sorted.\u003c/p\u003e\n"],["\u003cp\u003eProperties \u003ccode\u003eexpression\u003c/code\u003e, \u003ccode\u003edirection\u003c/code\u003e, and \u003ccode\u003edefault_value\u003c/code\u003e can be retrieved from an instance of \u003ccode\u003eSortExpression\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# The SortExpression Class\n\nClass `SortExpression` allows you to customize how your search results are sorted.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| python3\n|\n| /services/access). If you are updating to the App Engine Python 3 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/python-differences) to learn about your migration options for legacy bundled services.\n\n`SortExpression` is defined in the `google.appengine.api.search` module.\n\nConstructor\n-----------\n\nThe constructor for class `SortExpression` is defined as follows:\n\n\nclass SortExpression(expression=None, direction=DESCENDING, default_value=None)\n\n:\n Sort results by the specified scoring expression.\n\n:\n\n Arguments\n\n expression\n\n : 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\n `_score + count(likes) * 0.1`\n which will add the score from a scorer to a count of the values of a\n `likes` field weighted by a factor of 0.1.\n\n direction\n\n : The direction to sort the search results, either ASCENDING or DESCENDING.\n\n default_value\n\n : 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.\n\n Result value\n\n : A new instance of class `SortExpression`.\n\n Exceptions\n\n TypeError\n\n : If any of the parameters have an invalid type, or an unknown attribute is passed.\n\n ValueError\n\n : If any parameter has an invalid value.\n\n \u003cbr /\u003e\n\nProperties\n----------\n\nAn instance of class `SortExpression` has the following properties:\n\nexpression\n\n: Returns the expression used to sort matched results.\n\ndirection\n\n: Returns the direction of sort expression: `ASCENDING` or `DESCENDING`.\n\ndefault_value\n\n: Returns a default value for the expression if no other value could be computed."]]