Python 2.7 has reached end of supportand will bedeprecatedon January 31, 2026. After deprecation, you won't be able to deploy Python 2.7applications, even if your organization previously used an organization policy tore-enable deployments of legacy runtimes. Your existing Python2.7 applications will continue to run and receive traffic after theirdeprecation date. We recommend thatyoumigrate to the latest supported version of Python.

The Document Class

ClassDocument represents a document containing searchable content.

This API is supported for first-generation runtimes and can be used whenupgrading to corresponding second-generation runtimes. If you are updating to the App Engine Python 3 runtime, refer to themigration guide to learn about your migration options for legacy bundled services.

Document is defined in the modulegoogle.appengine.api.search.

Constructor

The constructor for classDocument is defined as follows:

class Document(doc_id=None,fields=None,language='en',rank=None)

Construct an instance of classDocument.

The following example shows how to create a document consisting of a set of fields, some plain text and one in HTML:

fromgoogle.appengine.apiimportsearchsearch.Document(doc_id='documentId',fields=[search.TextField(name='subject',value='going for dinner'),search.HtmlField(name='body',value='<html>I found a place.</html>'),search.TextField(name='signature',value='brzydka pogoda',language='pl')],language='en')

Arguments

doc_id

Thedocument identifier, a human-readable ASCII string identifying the document. Must contain no whitespace characters and not start with an exclamation point (!). If omitted, the search service will provide an identifier string.

In most cases, you do not need to specify the document identifier explicitly. Specifying your own identifier is useful, however, for implementing search with other storage mechanisms, such as Blobstore or Google Storage. In the case of Blobstore, for example, you can set the document identifier to theBlobKey in order to associate that document with a specific blob.

fields

An iterable collection ofField objects representing the content of the document.

language

A two-letterISO 693-1 code for the language in which the document's field values are expressed.

rank

The document'srank, an integer specifying the order in which it will be returned in search results. Newer documents are returned first. If not specified the rank will be set to the number of seconds since 1 January 2011 00:00:00 UTC.Note that when rank is used in a FieldExpression or SortExpression it is referenced as_rank.

Result value

A new instance of classDocument.

Exceptions

TypeError

A parameter has an invalid type or an unknown attribute was passed.

ValueError

A parameter has an invalid value.

Properties

An instance of classDocument has the following properties:

doc_id

The document identifier, a human-readable ASCII string identifying the document.

fields

A list of the document'sfields.

language

The two-letterISO 693-1 code for the language in which the document's field values are expressed.

rank

The document's rank, an integer specifying the order in which it will be returned in search results.Note that when rank is used in a FieldExpression or SortExpression it is referenced as_rank.Also, if you create a SortExpression that includes rank as one of the sort keys, rank can only be sorted inthe DESCENDING direction.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.