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 ScoredDocument

Stay organized with collections Save and categorize content based on your preferences.

Class ScoredDocument represents a scored document returned from a search. You do not build this class explicitly; rather, it is returned as a result of Index.search().

Caution: **This solution is no longer recommended:** Apps that use this API can only run in the Python 2 runtime and will need to upgrade to a [recommended solution](/appengine/docs/legacy/standard/python/migrate-to-python3/migrating-services#migration_paths_for_bundled_services) before migrating to the Python 3 runtime.

ScoredDocument is defined in the google.appengine.api.search module.

Constructor

The constructor for class MatchScorer is defined as follows:

class ScoredDocument(doc_id=None, fields=None, language='en', sort_scores=None, expressions=None, cursor=None, rank=None)

Represents a scored document returned from a search.

Arguments

doc_id

The visible, printable ASCII string identifying the document. Must not begin with '!'. Whitespace is excluded from ids. If no id is provided, the search service will provide one.

fields

An iterable of Field instances representing the content of the document.

language

The two-letter ISO 639.2 language code of the language used in the field values.

sort_scores

The list of scores assigned during sort evaluation. Each sort dimension is included. Positive scores are used for ascending sorts; negative scores for descending.

expressions

The list of computed fields which are the result of expressions requested.

cursor

A cursor associated with the document.

rank

The document rank is used to specify the order this document will be returned in search results, where 0 <= rank <= sys.maxint. If not specified, the number of seconds since 1st Jan 2011 is used. Documents are returned in descending order of the order ID.

Result value

A new instance of class ScoredDocument.

Exceptions

TypeError

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

ValueError

If any parameter has an invalid value.

Properties

An instance of class ScoredDocument has the following properties:

sort_scores

Returns the list of scores assigned while the API is sorting the results of a search. Each sort dimension is included. Positive scores are used for ascending sorts and negative scores for descending.

expressions

The list of computed fields the result of expression evaluation. For example, the following field expression seeks to compute a snippet field containing HTML snippets extracted from the matching of the query 'good story' in the content field:

FieldExpression(name='snippet', 'snippet("good story", content)')
Given this query, the API would return the following ScoredDocument.expression:
HtmlField(name='snippet', value='that was a good story to finish')

cursor

A cursor associated with a result used as a starting point from which to return the next set of search results. This property will not return unless you set the Index.cursor_type to Index.RESULT_CURSOR; otherwise the property returns be None.