Klasse "SortOptions"
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Die Klasse SortExpression
ermöglicht eine mehrdimensionale Sortierung von Dokumenten.
Mit dem folgenden Codebeispiel werden Dokumente basierend auf der Produktbewertung in absteigender Reihenfolge sortiert. Anschließend wird nach dem preisgünstigsten Produkt innerhalb der ähnlich bewerteten Produkte sortiert und ein Limit von 1.000 Dokumenten festgelegt:
SortOptions(expressions=[
SortExpression(expression='rating',
direction=SortExpression.DESCENDING, default_value=0),
SortExpression(expression='price + tax',
direction=SortExpression.ASCENDING, default_value=999999.99)],
limit=1000)
SortOptions
ist im Modul google.appengine.api.search
definiert.
Konstruktor
Der Konstruktor für die Klasse SortOptions
ist so definiert:
-
Klasse SortOptions(expressions=None, match_scorer=None, limit=1.000)
Sortiert Dokumente anhand der angegebenen Optionen.
Argumente
- expressions
Ein iterierbares Element von SortExpression, das eine mehrdimensionale Sortierung von Dokumenten darstellt.
- match_scorer
Eine Spezifikation für die Übereinstimmung mit einer Punktzahl, die zur Bewertung von Dokumenten oder in einer SortExpression kombiniert mit anderen Funktionen verwendet werden kann.
- limit
Die höchste Anzahl der zu bewertenden Dokumente. Bei großen Indexen empfiehlt es sich, ein Limit festzulegen.
Ergebniswert
Eine neue Instanz der Klasse SortOptions
.
Ausnahmen
- TypeError
Wenn einer der Parameter einen ungültigen Typ hat oder ein unbekanntes Attribut übergeben wird.
- ValueError
Wenn einer der Parameter einen ungültigen Wert hat.
Eigenschaften
Eine Instanz der Klasse SortOptions
hat die folgenden Attribute:
- expressions
Gibt eine Liste von SortExpressions zurück, in denen eine mehrdimensionale Sortierung angegeben wird.
- match_scorer
Gibt eine Übereinstimmung mit einer Punktzahl zurück, mit der Dokumente bewertet werden.
- limit
Gibt die höchste Anzahl der zu bewertenden Dokumente zurück.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-09-04 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[[["\u003cp\u003eThe \u003ccode\u003eSortOptions\u003c/code\u003e class enables multi-dimensional sorting of documents, leveraging \u003ccode\u003eSortExpression\u003c/code\u003e for detailed control.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSortOptions\u003c/code\u003e allows specifying sorting criteria using an iterable of \u003ccode\u003eSortExpression\u003c/code\u003e, a match scorer, and a limit on the number of documents to sort.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eSortOptions\u003c/code\u003e constructor can be configured with \u003ccode\u003eexpressions\u003c/code\u003e, \u003ccode\u003ematch_scorer\u003c/code\u003e, and \u003ccode\u003elimit\u003c/code\u003e, throwing \u003ccode\u003eTypeError\u003c/code\u003e or \u003ccode\u003eValueError\u003c/code\u003e if input is invalid.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSortExpression\u003c/code\u003e objects can define the direction of sorting, such as ascending or descending, and a default value for the sort key.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSortOptions\u003c/code\u003e properties \u003ccode\u003eexpressions\u003c/code\u003e, \u003ccode\u003ematch_scorer\u003c/code\u003e, and \u003ccode\u003elimit\u003c/code\u003e allow you to access the configured settings for sorting.\u003c/p\u003e\n"]]],[],null,["# The SortOptions Class\n\nClass `SortExpression` represents a multi-dimensional sort of Documents.\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\nThe following code shows how to sort documents based on product rating\nin descending order and then cheapest product within similarly rated\nproducts, sorting at most 1000 documents: \n\n```python\n SortOptions(expressions=[\n SortExpression(expression='rating',\n direction=SortExpression.DESCENDING, default_value=0),\n SortExpression(expression='price + tax',\n direction=SortExpression.ASCENDING, default_value=999999.99)],\n limit=1000)\n```\n\n`SortOptions` is defined in the `google.appengine.api.search` module.\n\nConstructor\n-----------\n\nThe constructor for class `SortOptions` is defined as follows:\n\n\nclass SortOptions(expressions=None, match_scorer=None, limit=1000)\n\n:\n Sort documents according to the specified options.\n\n:\n\n Arguments\n\n expressions\n\n : An iterable of SortExpression representing a multi-dimensional sort of Documents.\n\n match_scorer\n\n : A match scorer specification which may be used to score documents or in a SortExpression combined with other features.\n\n limit\n\n : The limit on the number of documents to score. It is advisable to set this limit on large indexes.\n\n Result value\n\n : A new instance of class `SortOptions`.\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 `SortOptions` has the following properties:\n\nexpressions\n\n: Returns a list of SortExpression specifying a multi-dimensional sort.\n\nmatch_scorer\n\n: Returns a match scorer used to score documents.\n\nlimit\n\n: Returns the limit on the number of documents to score."]]