Python 2.7 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Python.
The Document Class
Stay organized with collections
Save and categorize content based on your preferences.
Class Document
represents a document containing searchable content.
Document
is defined in the module google.appengine.api.search
.
Constructor
The constructor for class Document
is defined as follows:
- class Document(doc_id=None, fields=None, language='en', rank=None)
Construct an instance of class Document
.
The following example shows how to create a document consisting of a set of fields, some plain text and one in HTML:
from google.appengine.api import search
search.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
The document 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 the BlobKey
in order to associate that document with a specific blob.
- fields
An iterable collection of Field
objects representing the content of the document.
- language
A two-letter ISO 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. 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 class Document
.
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 class Document
has the following properties:
- doc_id
The document identifier, a human-readable ASCII string identifying the document.
- fields
A list of the document's fields.
- language
The two-letter ISO 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 in
the DESCENDING direction.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-25 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eDocument\u003c/code\u003e class represents a searchable document and is defined within the \u003ccode\u003egoogle.appengine.api.search\u003c/code\u003e module.\u003c/p\u003e\n"],["\u003cp\u003eYou can construct a \u003ccode\u003eDocument\u003c/code\u003e instance by specifying a \u003ccode\u003edoc_id\u003c/code\u003e, an iterable collection of \u003ccode\u003eField\u003c/code\u003e objects, the language of the document, and an optional rank for search result ordering.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003edoc_id\u003c/code\u003e is a unique identifier for the document, and if not provided, the search service will automatically assign one.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003erank\u003c/code\u003e property determines the document's order in search results, with newer documents returned first, and if not specified, defaults to seconds since January 1, 2011.\u003c/p\u003e\n"],["\u003cp\u003eThe document language can be defined by the use of a two-letter \u003ca href=\"https://iso639-3.sil.org/\"\u003eISO 693-1\u003c/a\u003e code.\u003c/p\u003e\n"]]],[],null,["# The Document Class\n\nClass `Document` represents a document containing searchable content.\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\n`Document` is defined in the module `google.appengine.api.search`.\n\nConstructor\n-----------\n\nThe constructor for class `Document` is defined as follows:\n\nclass Document(doc_id=None, fields=None, language='en', rank=None)\n\n: Construct an instance of class `Document`.\n\n The following example shows how to create a document consisting of a set of fields, some plain text and one in HTML: \n\n ```python\n from google.appengine.api import search\n\n search.Document(\n doc_id='documentId',\n fields=[search.TextField(name='subject', value='going for dinner'),\n search.HtmlField(name='body', value='\u003chtml\u003eI found a place.\u003c/html\u003e'),\n search.TextField(name='signature', value='brzydka pogoda', language='pl')],\n language='en')\n ```\n\n \u003cbr /\u003e\n\n:\n\n Arguments\n\n doc_id\n\n : The *document 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.\n\n\n 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 the [BlobKey](/appengine/docs/legacy/standard/python/refdocs/google.appengine.ext.blobstore.blobstore#google.appengine.ext.blobstore.blobstore.BlobKey) in order to associate that document with a specific blob.\n\n fields\n\n : An iterable collection of `Field` objects representing the content of the document.\n\n language\n\n : A two-letter [ISO 693-1](https://iso639-3.sil.org/) code for the language in which the document's field values are expressed.\n\n rank\n\n : The document's *rank,* 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.\n Note that when rank is used in a FieldExpression or SortExpression it is referenced as `_rank`.\n\n Result value\n\n : A new instance of class `Document`.\n\n Exceptions\n\n TypeError\n\n : A parameter has an invalid type or an unknown attribute was passed.\n\n ValueError\n\n : A parameter has an invalid value.\n\n \u003cbr /\u003e\n\n\u003cbr /\u003e\n\nProperties\n----------\n\nAn instance of class `Document` has the following properties:\n\ndoc_id\n\n: The document identifier, a human-readable ASCII string identifying the document.\n\nfields\n\n: A list of the document's [fields](/appengine/docs/legacy/standard/python/search/fieldclasses).\n\nlanguage\n\n: The two-letter [ISO 693-1](https://iso639-3.sil.org/) code for the language in which the document's field values are expressed.\n\nrank\n\n: The document's rank, an integer specifying the order in which it will be returned in search results.\n Note that when rank is used in a FieldExpression or SortExpression it is referenced as `_rank`.\n Also, if you create a SortExpression that includes rank as one of the sort keys, rank can only be sorted in\n the DESCENDING direction."]]