Klasse MatchScorer
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Mit der
MatchScorer
-Klasse können Sie Dokumente basierend auf der Qualität der Abfrageübereinstimmung sortieren. Der Scorer weist eine Punktzahl anhand der Begriffshäufigkeit in einem Dokument zu.
Wenn Sie MatchScorer
verwenden möchten, fügen Sie ihn in SortOptions
ein wie im Folgenden dargestellt:
sort_opts = search.SortOptions(match_scorer=search.MatchScorer())
Damit werden die Dokumente nach absteigender Punktzahl sortiert. Die Punktzahlen sind positiv.
Wenn Sie in aufsteigender Reihenfolge sortieren möchten, verwenden Sie folgenden Code:
sort_opts = search.SortOptions(match_scorer=search.MatchScorer(),
expressions=[search.SortExpression(
expression='_score', direction=search.SortExpression.ASCENDING,
default_value=0.0)])
Die Punktzahlen sind in diesem Fall negativ.
MatchScorer
ist im Modul google.appengine.api.search
definiert.
Konstruktor
Der Konstruktor für die Klasse MatchScorer
ist so definiert:
- class MatchScorer()
Weist Suchergebnissen eine Dokumentpunktzahl zu. Diese gibt anhand der Häufigkeit der Begriffe im Dokument an, wie gut die Ergebnisse mit der Abfrage übereinstimmen.
Ergebniswert
Eine neue Instanz der Klasse MatchScorer
.
Ausnahmen
- TypeError
Wenn einer der Parameter einen ungültigen Typ hat oder ein unbekanntes Attribut übergeben wird.
- ValueError
Wenn ein Parameter einen ungültigen Wert aufweist.
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-03 (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-03 (UTC)."],[[["\u003cp\u003eThe \u003ccode\u003eMatchScorer\u003c/code\u003e class allows sorting of documents based on the quality of their match to a query by assigning a score based on term frequency.\u003c/p\u003e\n"],["\u003cp\u003eAdding \u003ccode\u003eMatchScorer\u003c/code\u003e to \u003ccode\u003eSortOptions\u003c/code\u003e sorts documents in descending score order, resulting in positive scores.\u003c/p\u003e\n"],["\u003cp\u003eTo sort in ascending order, use \u003ccode\u003eMatchScorer\u003c/code\u003e within \u003ccode\u003eSortOptions\u003c/code\u003e with a \u003ccode\u003eSortExpression\u003c/code\u003e set to \u003ccode\u003eASCENDING\u003c/code\u003e, which results in negative scores.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMatchScorer\u003c/code\u003e class is in the \u003ccode\u003egoogle.appengine.api.search\u003c/code\u003e module, and if an invalid type or value is passed as parameters, a \u003ccode\u003eTypeError\u003c/code\u003e or \u003ccode\u003eValueError\u003c/code\u003e will be raised.\u003c/p\u003e\n"]]],[],null,["# class MatchScorer\n\nClass `MatchScorer` allows you to sort documents based on the quality of query match. The scorer assigns a score based on term frequency in a document.\n\n\u003cbr /\u003e\n\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\nTo use a `MatchScorer`, add it to the `SortOptions` as in the following code: \n\n```python\n sort_opts = search.SortOptions(match_scorer=search.MatchScorer())\n```\n\nThis sorts the documents in descending score order. The scores will be\npositive.\n\nIf you want to sort in ascending order, then use the following code: \n\n```python\n sort_opts = search.SortOptions(match_scorer=search.MatchScorer(),\n expressions=[search.SortExpression(\n expression='_score', direction=search.SortExpression.ASCENDING,\n default_value=0.0)])\n```\n\nThe scores in this case will be negative.\n\n`MatchScorer` is defined in the `google.appengine.api.search` module.\n\nConstructor\n-----------\n\nThe constructor for class `MatchScorer` is defined as follows:\n\nclass MatchScorer()\n\n: Assigns a document score to search results representing how well they match the query, base on frequency of terms in the document.\n\n Result value\n\n : A new instance of class `MatchScorer`.\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"]]