Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
Document クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Document
クラスは、検索可能なコンテンツを含むドキュメントを表します。
Document
は、google.appengine.api.search
モジュールで定義されます。
コンストラクタ
Document
クラスのコンストラクタは、次のように定義されます。
- class Document(doc_id=None, fields=None, language='en', rank=None)
クラス Document
のインスタンスを作成します。
次の例は、書式なしテキストと 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')
引数
- doc_id
ドキュメント ID。人間が読み取れる形式の ASCII 文字列で、ドキュメントを識別します。空白文字を含めることはできません。また、先頭に感嘆符(!
)は使用できません。省略した場合、検索サービスにより ID 文字列が提供されます。
ほとんどの場合、ドキュメント ID を明示的に指定する必要はありません。ただし、独自の ID を指定すると、他のストレージ メカニズム(Blobstore や Google ストレージなど)で検索を実施する際に便利です。たとえば Blobstore の場合、ドキュメント ID を BlobKey
に設定して、そのドキュメントを特定の blob に関連付けることができます。
- fields
ドキュメントのコンテンツを表す Field
オブジェクトの反復可能なコレクション。
- language
ドキュメントのフィールド値の記述に使用される言語を表す、2 文字の ISO 693-1 コード。
- rank
ドキュメントの rank。検索結果で返される順序を整数で指定します。新しいドキュメントから先に返されます。指定しない場合、rank は 2011 年 1 月 1 日 00:00:00(UTC)以降経過した秒数に設定されます。FieldExpression または SortExpression で rank を使用する場合は、_rank
として参照されます。
結果値
Document
クラスの新しいインスタンス。
例外
- TypeError
パラメータのタイプが無効であるか、不明な属性が渡されました。
- ValueError
パラメータの値が無効です。
特性
Document
クラスのインスタンスには次のプロパティがあります。
- doc_id
ドキュメント ID。人間が読み取れる形式の ASCII 文字列で、ドキュメントを識別します。
- fields
ドキュメントのフィールドのリスト。
- language
ドキュメントのフィールド値の記述に使用される言語を表す、2 文字の ISO 693-1 コード。
- rank
ドキュメントの rank。検索結果で返される順序を整数で指定します。FieldExpression または SortExpression で rank を使用する場合は、_rank
として参照されます。また、ソートキーの 1 つとして rank を含む SortExpression を作成する場合、rank の並べ替えは降順でのみ可能です。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-11 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-08-11 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."]]