Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

class MatchScorer

Class 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.

To use a MatchScorer, add it to the SortOptions as in the following code:

  sort_opts = search.SortOptions(match_scorer=search.MatchScorer())

This sorts the documents in descending score order. The scores will be positive.

If you want to sort in ascending order, then use the following code:

  sort_opts = search.SortOptions(match_scorer=search.MatchScorer(),
          expression='_score', direction=search.SortExpression.ASCENDING,

The scores in this case will be negative.

MatchScorer is defined in the module.


The constructor for class MatchScorer is defined as follows:

class MatchScorer()

Assigns a document score to search results representing how well they match the query, base on frequency of terms in the document.

Result value

A new instance of class MatchScorer.



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


If any parameter has an invalid value.