Die Klasse Document
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Die Klasse Document
stellt ein Dokument mit durchsuchbarem Inhalt dar.
Document
ist im Modul google.appengine.api.search
definiert.
Konstruktor
Der Konstruktor für die Klasse Document
ist so definiert:
- Klasse Document(doc_id=None, fields=None, language='en', rank=None)
Konstruieren Sie eine Instanz der Klasse Document
.
Im folgenden Beispiel wird ein Dokument erstellt, das aus einer Reihe von Feldern besteht, von denen einige im Nur-Text- und andere im HTML-Format vorliegen.
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')
Argumente
- doc_id
Die Dokument-ID, eine von Menschen lesbare ASCII-Zeichenfolge, die das Dokument identifiziert. Er darf keine Leerzeichen enthalten und nicht mit einem Ausrufezeichen (!
) beginnen. Ohne Angabe stellt der Suchdienst einen ID-String bereit.
In den meisten Fällen müssen Sie die Dokument-ID nicht explizit angeben. Die Angabe einer eigenen ID ist jedoch für die Suche mit anderen Speichermechanismen wie Blobstore oder Google Storage hilfreich. Im Fall von Blobstore können Sie zum Beispiel die Dokument-ID auf den BlobKey
setzen, um dieses Dokument einem bestimmten Blob zuzuordnen.
- fields
Eine iterierbare Sammlung von Field
-Objekten, die den Inhalt des Dokuments darstellen.
- Sprache
Ein Code mit zwei Buchstaben nach ISO 693-1 für die Sprache, in der die Feldwerte des Dokuments ausgedrückt werden.
- rank
Der Rang des Dokuments als Ganzzahl. Diese gibt die Reihenfolge an, in der das Dokument in den Suchergebnissen zurückgegeben wird. Neuere Dokumente werden zuerst zurückgegeben. Ohne sonstige Angabe des Rangs wird dieser auf die Anzahl der Sekunden seit dem 1. Januar 2011 00:00:00 UTC festgelegt.
Ein Rang wird als _rank
referenziert, wenn er in einem Feldausdruck (FieldExpression) oder Sortierausdruck (SortExpression) verwendet wird.
Ergebniswert
Eine neue Instanz der Klasse Document
.
Ausnahmen
- TypeError
Ein Parameter hat einen ungültigen Typ oder ein unbekanntes Attribut wurde übergeben.
- ValueError
Ein Parameter hat einen ungültigen Wert.
Eigenschaften
Eine Instanz der Klasse Document
hat die folgenden Attribute:
- doc_id
Die Dokument-ID, eine von Menschen lesbare ASCII-Zeichenfolge, die das Dokument identifiziert.
- fields
Eine Liste der Felder des Dokuments.
- Sprache
Ein Code mit zwei Buchstaben nach ISO 693-1 für die Sprache, in der die Feldwerte des Dokuments ausgedrückt werden.
- rank
Der Rang des Dokuments als Ganzzahl. Diese gibt die Reihenfolge an, in der das Dokument in den Suchergebnissen zurückgegeben wird.
Ein Rang wird als _rank
referenziert, wenn er in einem Feldausdruck (FieldExpression) oder Sortierausdruck (SortExpression) verwendet wird.
Wenn Sie eine SortExpression mit dem Rang als einen der Sortierschlüssel erstellen, kann der Rang nur in ABSTEIGENDER Richtung sortiert werden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-09-03 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-03 (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."]]