Feldklassen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Die Klasse Field
ist eine abstrakte Basisklasse, die ein Feld eines Dokuments darstellt. Diese Klasse sollte nicht direkt instanziiert werden. Verwenden Sie stattdessen eine der abgeleiteten Klassen, die bestimmte Datentypen darstellen.
Field
ist im Modul google.appengine.api.search
definiert.
Eigenschaften
Eine Instanz der Klasse Field
hat die folgenden Attribute:
- name
Name des Feldes. Muss mit einem Buchstaben beginnen, darf nur Buchstaben, Ziffern und Unterstriche (_
) enthalten und höchstens 500 Zeichen lang sein.
- Sprache
Sprachcode mit zwei Buchstaben nach ISO 693-1 für den Inhalt des Feldes zur Unterstützung der Vergabe eines Tokens. Beispiel: en
bedeutet, dass die Sprache im Feld Englisch ist. Bei None
wird der Sprachcode des Dokuments herangezogen.
- Wert
Wert des Feldes. Der Datentyp hängt von der jeweiligen abgeleiteten Klasse ab.
Abgeleitete Klassen
Die Klasse Field
hat die folgenden abgeleiteten Klassen:
-
Klasse TextField
Ein Feld, das Text enthält.
Der Wert des Feldes muss ein String oder ein Unicode-String sein. The following example shows a text field named signature
with Polish language content:
TextField(name='signature', value='brzydka pogoda', language='pl')
-
Ausnahmen
- TypeError
Der angegebene Wert ist kein Textstring.
- ValueError
Der Wert überschreitet die maximal zulässige Länge.
-
Klasse HtmlField
Ein Feld mit HTML-Inhalt.
Der Wert des Feldes muss ein String oder ein Unicode-String mit dem durchsuchbaren Inhalt des Feldes sein. Das folgende Beispiel zeigt ein HTML-Feld mit dem Namen content
:
HtmlField(name='content', value='<html>herbata, kawa</html>', language='pl')
-
Ausnahmen
- TypeError
Der angegebene Wert ist kein Textstring.
- ValueError
Der Wert überschreitet die maximal zulässige Länge.
-
Klasse AtomField
Ein Feld, das Text enthält, der für Indexierungszwecke als unteilbares (atomares) Token behandelt werden soll.
Der Wert des Feldes muss ein String oder ein Unicode-Objekt sein, der bzw. das als unteilbares Token behandelt werden soll. Das folgende Beispiel zeigt ein Atomfeld mit dem Namen contributor
:
AtomField(name='contributor', value='foo@bar.com')
-
Ausnahmen
- TypeError
Der angegebene Wert ist kein Textstring.
- ValueError
Der Wert überschreitet die maximal zulässige Länge.
-
Klasse NumberField
Ein Feld, das einen numerischen Wert enthält.
Der Wert des Feldes muss numerisch sein. Das folgende Beispiel zeigt ein Zahlenfeld namens size
mit dem Ganzzahlwert 10:
NumberField(name='size', value=10)
Ausnahme
- TypeError
Der angegebene Wert ist nicht numerisch.
-
Klasse DateField
Ein Feld, das einen Datums- oder Datum/Uhrzeit-Wert enthält.
The field's value must be of type datetime.date
, or datetime.datetime
.
In Python können nur "naive" Datums- und Uhrzeitobjekte verwendet werden. "Bewusste" Objekte sind nicht zulässig.
The following example shows a date field named creation_date
representing the date 21 March 2011:
DateField(name='creation_date', value=datetime.date(2011, 03, 21))
Ausnahme
- TypeError
Der angegebene Wert ist weder ein datetime.date
noch ein datetime.datetime
.
-
class GeoField
Ein Feld, das einen Wert vom Typ GeoPoint enthält.
Das folgende Beispiel zeigt ein GeoField mit dem Namen place
, das einen Standort bei Breitengrad -33,84 und Längengrad 151,26 darstellt:
GeoField(name='place', value=GeoPoint(latitude=-33.84, longitude=151.26))
Ausnahme
- TypeError
Der angegebene Wert ist kein GeoPoint
.
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\u003eField\u003c/code\u003e class is an abstract base class for document fields and should not be directly instantiated; subclasses should be used instead.\u003c/p\u003e\n"],["\u003cp\u003eEach \u003ccode\u003eField\u003c/code\u003e instance has properties for \u003ccode\u003ename\u003c/code\u003e, \u003ccode\u003elanguage\u003c/code\u003e, and \u003ccode\u003evalue\u003c/code\u003e, with specific constraints on the \u003ccode\u003ename\u003c/code\u003e format and the \u003ccode\u003evalue\u003c/code\u003e data type.\u003c/p\u003e\n"],["\u003cp\u003eThere are six subclasses of \u003ccode\u003eField\u003c/code\u003e: \u003ccode\u003eTextField\u003c/code\u003e, \u003ccode\u003eHtmlField\u003c/code\u003e, \u003ccode\u003eAtomField\u003c/code\u003e, \u003ccode\u003eNumberField\u003c/code\u003e, \u003ccode\u003eDateField\u003c/code\u003e, and \u003ccode\u003eGeoField\u003c/code\u003e, each designed for different data types like text, HTML, atomic tokens, numbers, dates, and geographic locations, respectively.\u003c/p\u003e\n"],["\u003cp\u003eEach subclass of \u003ccode\u003eField\u003c/code\u003e has specific data type requirements for the \u003ccode\u003evalue\u003c/code\u003e property and will raise a \u003ccode\u003eTypeError\u003c/code\u003e if an incorrect type is provided.\u003c/p\u003e\n"],["\u003cp\u003eThe different subclasses will raise \u003ccode\u003eValueError\u003c/code\u003e exceptions if the \u003ccode\u003evalue\u003c/code\u003e exceeds the maximum allowable length.\u003c/p\u003e\n"]]],[],null,["# Field Classes\n\nClass `Field` is an abstract base class representing a field of a document. This class should not be directly instantiated; instead, use one of the subclasses representing specific data types.\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`Field` is defined in the module `google.appengine.api.search`.\n\nProperties\n----------\n\nAn instance of class `Field` has the following properties:\n\nname\n\n: Name of the field. Must begin with a letter, contain only letters, digits, and underscores (`_`), and be no longer than 500 characters.\n\nlanguage\n\n: Two-letter [ISO 693-1](http://www.sil.org/iso639-3/codes.asp?order=639_1&letter=%25) language code for the field's content, to assist in tokenization. For example, `en` signifies that the field is English. If `None`, the language code of the document will be used.\n\nvalue\n\n: Value of the field. Data type varies depending on the specific subclass.\n\nSubclasses\n----------\n\nClass `Field` has the following subclasses:\n\n\nclass TextField\n\n: A field containing text.\n\n The field's value must be a string or Unicode string. The following example shows a text field named `signature` with Polish language content: \n\n ```\n TextField(name='signature', value='brzydka pogoda', language='pl')\n ```\n\n: Exceptions\n\n TypeError\n\n : Value supplied is not a text string.\n\n ValueError\n\n : Value exceeds maximum allowable length.\n\n\nclass HtmlField\n\n: A field containing HTML content.\n\n The field's value must be a string or Unicode string containing the searchable content of the field. The following example shows an HTML field named `content`: \n\n ```\n HtmlField(name='content', value='\u003chtml\u003eherbata, kawa\u003c/html\u003e', language='pl')\n ```\n\n: Exceptions\n\n TypeError\n\n : Value supplied is not a text string.\n\n ValueError\n\n : Value exceeds maximum allowable length.\n\n\nclass AtomField\n\n: A field containing text to be treated as an indivisible (atomic) token for indexing purposes.\n\n The field's value must be a string or Unicode object to be treated as an atomic token. The following example shows an atom field named `contributor`: \n\n ```\n AtomField(name='contributor', value='foo@bar.com')\n ```\n\n: Exceptions\n\n TypeError\n\n : Value supplied is not a text string.\n\n ValueError\n\n : Value exceeds maximum allowable length.\n\n\nclass NumberField\n\n: A field containing a numeric value.\n\n The field's value must be numeric. The following example shows a number field named `size` with integer value 10: \n\n ```\n NumberField(name='size', value=10)\n ```\n\n: **Exception**\n\n TypeError\n\n : Value supplied is not numeric.\n\n\nclass DateField\n\n: A field containing a date or datetime value.\n\n The field's value must be of type `datetime.date`, or `datetime.datetime`.\n Only Python [\"naive\"](https://docs.python.org/2/library/datetime.html) date and time objects can be used. \"Aware\" objects are not allowed.\n The following example shows a date field named `creation_date` representing the date 21 March 2011: \n\n ```\n DateField(name='creation_date', value=datetime.date(2011, 03, 21))\n ```\n\n:\n\n **Exception**\n\n TypeError\n\n : Value supplied is not a `datetime.date` or a `datetime.datetime`.\n\n\nclass GeoField\n\n: A field containing a [GeoPoint](/appengine/docs/legacy/standard/python/search/geopointclass) value.\n\n The following example shows a GeoField named `place` representing a location at -33.84 degrees latitude and 151.26 degrees longitude: \n\n ```\n GeoField(name='place', value=GeoPoint(latitude=-33.84, longitude=151.26))\n ```\n\n:\n\n **Exception**\n\n TypeError\n\n : Value supplied is not a [GeoPoint](/appengine/docs/legacy/standard/python/search/geopointclass)."]]