[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-20。"],[[["\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"]]