Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
Field クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Field
クラスは、ドキュメントのフィールドを表す基本の抽象クラスです。このクラスを直接インスタンス化しないでください。代わりに、特定のデータタイプを表すサブクラスのいずれか一つを使用してください。
Field
は、google.appengine.api.search
モジュールで定義されます。
プロパティ
Field
クラスのインスタンスには次のプロパティがあります。
- name
フィールドの名前。文字で始め、文字、数字、アンダースコア(_
)のみ使用できます。長さは 500 文字以下にする必要があります。
- language
フィールド コンテンツ用の 2 文字の ISO 693-1 言語コード。トークン化に役立ちます。たとえば、en
はフィールドが英語であることを示します。None
の場合、ドキュメントの言語コードが使用されます。
- value
フィールドの値。データ タイプはサブクラスによって異なります。
サブクラス
Field
クラスには次のサブクラスがあります。
- class TextField
テキストを含むフィールド。
このフィールドの値は、文字列または Unicode 文字列でなければなりません。次の例は、コンテンツがポーランド語である signature
という名前のテキスト フィールドを示しています。
TextField(name='signature', value='brzydka pogoda', language='pl')
-
例外
- TypeError
指定された値がテキスト文字列ではありません。
- ValueError
値が、許容される長さの上限を超えています。
- class HtmlField
HTML コンテンツを含むフィールド。
このフィールドの値は、フィールドの検索可能コンテンツを含む文字列または Unicode 文字列でなければなりません。次の例は、content
という名前の HTML フィールドを示しています。
HtmlField(name='content', value='<html>herbata, kawa</html>', language='pl')
-
例外
- TypeError
指定された値がテキスト文字列ではありません。
- ValueError
値が、許容される長さの上限を超えています。
- class AtomField
インデックス作成のために不可分の(アトミック)トークンとして扱われるテキストを含むフィールド。
このフィールドの値は、アトミック トークンとして処理される文字列または Unicode オブジェクトでなければなりません。次の例は、contributor
という名前のアトム フィールドを示しています。
AtomField(name='contributor', value='foo@bar.com')
-
例外
- TypeError
指定された値がテキスト文字列ではありません。
- ValueError
値が、許容される長さの上限を超えています。
- class NumberField
数値を含むフィールド。
このフィールドの値は、数字でなければなりません。次の例は、整数値が 10 である size
という名前の数字フィールドを示しています。
NumberField(name='size', value=10)
例外
- TypeError
指定された値が数字ではありません。
- class DateField
日付または日時の値を含むフィールド。
フィールドの値は、datetime.date
または datetime.datetime
型にする必要があります。使用できるのは、Python ネイティブの日時オブジェクトだけです。"Aware" オブジェクトは使用できません。次の例は、2011 年 3 月 21 日を表す creation_date
という名前の日付フィールドを示しています。
DateField(name='creation_date', value=datetime.date(2011, 03, 21))
例外
- TypeError
指定された値が datetime.date
または datetime.datetime
ではありません。
- class GeoField
GeoPoint 値を含むフィールド。
次の例は、緯度が -33.84 度で経度が 151.26 度の場所を表す place
という名前の GeoField を示しています:
GeoField(name='place', value=GeoPoint(latitude=-33.84, longitude=151.26))
例外
- TypeError
指定された値が GeoPoint
ではありません。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 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)."]]