Stay organized with collections
Save and categorize content based on your preferences.
publicclassDocumentimplementsSerializable
Represents a user generated document. The following example shows how to
create a document consisting of a set of fields, some with plain text and
some in HTML; it also adds facets to the document.
Documentdocument=Document.newBuilder().setId("document id").setLocale(Locale.UK).addField(Field.newBuilder().setName("subject").setText("going for dinner")).addField(Field.newBuilder().setName("body").setHTML("I found a restaurant.")).addField(Field.newBuilder().setName("signature").setText("ten post jest przeznaczony dla odbiorcy").setLocale(newLocale("pl"))).addFacet(Facet.withAtom("tag","food")).addFacet(Facet.withNumber("priority",5.0)).build();
The following example shows how to access the fields within a document:
Creates a new document builder. You must use this method to obtain a new
builder. The returned builder must be used to specify all properties of
the document. To obtain the document call the Builder#build()
method on the returned builder.
Returns the rank of this document. A document's rank is used to
determine the default order in which documents are returned by
search, if no sorting or scoring is specified.
[[["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-09-03 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eDocument\u003c/code\u003e class represents a user-generated document that can contain fields with text, HTML, or other data types, and it is serializable.\u003c/p\u003e\n"],["\u003cp\u003eDocuments are created using a builder pattern, where you can add fields (e.g., subject, body, signature) and facets (e.g., tags, priority).\u003c/p\u003e\n"],["\u003cp\u003eFields within a document can be accessed via \u003ccode\u003edocument.getFields()\u003c/code\u003e, and their type (TEXT, HTML, ATOM, DATE) determines how the content is retrieved, via \u003ccode\u003efield.getText()\u003c/code\u003e or other get methods.\u003c/p\u003e\n"],["\u003cp\u003eFacets within a document can be accessed via \u003ccode\u003edocument.getFacets()\u003c/code\u003e, and their type (ATOM, NUMBER) will dictate the correct method, for example \u003ccode\u003efacet.getAtom()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDocument\u003c/code\u003e class has methods to retrieve specific fields or facets by name, via \u003ccode\u003egetFields(String name)\u003c/code\u003e and \u003ccode\u003egetFacets(String name)\u003c/code\u003e respectively, and methods to retrieve a count of them as well, via \u003ccode\u003egetFieldCount(String name)\u003c/code\u003e and \u003ccode\u003egetFacetCount(String name)\u003c/code\u003e respectively.\u003c/p\u003e\n"]]],[],null,["# Class Document (2.0.0)\n\n public class Document implements Serializable\n\nRepresents a user generated document. The following example shows how to\ncreate a document consisting of a set of fields, some with plain text and\nsome in HTML; it also adds facets to the document. \n\n\n Document document = Document.newBuilder().setId(\"document id\")\n .setLocale(Locale.UK)\n .addField(Field.newBuilder()\n .setName(\"subject\")\n .setText(\"going for dinner\"))\n .addField(Field.newBuilder()\n .setName(\"body\")\n .setHTML(\"I found a restaurant.\"))\n .addField(Field.newBuilder()\n .setName(\"signature\")\n .setText(\"ten post jest przeznaczony dla odbiorcy\")\n .setLocale(new Locale(\"pl\")))\n .addFacet(Facet.withAtom(\"tag\", \"food\"))\n .addFacet(Facet.withNumber(\"priority\", 5.0))\n .build();\n \nThe following example shows how to access the fields within a document: \n\n\n Document document = ...\n\n for (Field field : document.getFields()) {\n switch (field.getType()) {\n case TEXT: use(field.getText()); break;\n case HTML: use(field.getHtml()); break;\n case ATOM: use(field.getAtom()); break;\n case DATE: use(field.getDate()); break;\n }\n }\n \nAnd this example shows how to access the facets within a document: \n\n\n Document document = ...\n\n for (Facet facet : document.getFacets()) {\n switch (facet.getType()) {\n case ATOM: use(facet.getAtom()); break;\n case NUMBER: use(facet.getNumber()); break;\n }\n }\n \nInheritance\n-----------\n\n[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e Document \n\nImplements\n----------\n\n[Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### newBuilder()\n\n public static Document.Builder newBuilder()\n\nCreates a new document builder. You must use this method to obtain a new\nbuilder. The returned builder must be used to specify all properties of\nthe document. To obtain the document call the Builder#build()\nmethod on the returned builder.\n\nConstructors\n------------\n\n### Document(Document.Builder builder)\n\n protected Document(Document.Builder builder)\n\nConstructs a document with the given builder.\n\nMethods\n-------\n\n### equals(Object object)\n\n public boolean equals(Object object)\n\n**Overrides** \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)\n\n### getFacetCount(String name)\n\n public int getFacetCount(String name)\n\nReturns the number of times a facet with the given name is present\nin this document.\n\n### getFacetNames()\n\n public Set\u003cString\u003e getFacetNames()\n\nReturns an unmodifiable [Set](https://docs.oracle.com/javase/8/docs/api/java/util/Set.html) of the facet names in the document\n\n### getFacets()\n\n public Iterable\u003cFacet\u003e getFacets()\n\nReturns an iterable of [Facet](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Facet) in the document\n\n### getFacets(String name)\n\n public Iterable\u003cFacet\u003e getFacets(String name)\n\nReturns an iterable of all facets with the given name.\n\n### getFieldCount(String name)\n\n public int getFieldCount(String name)\n\nReturns the number of times a field with the given name is present\nin this document.\n\n### getFieldNames()\n\n public Set\u003cString\u003e getFieldNames()\n\nReturns an unmodifiable [Set](https://docs.oracle.com/javase/8/docs/api/java/util/Set.html) of the field names in the document\n\n### getFields()\n\n public Iterable\u003cField\u003e getFields()\n\nReturns an iterable of [Field](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Field) in the document\n\n### getFields(String name)\n\n public Iterable\u003cField\u003e getFields(String name)\n\nReturns an iterable of all fields with the given name.\n\n### getId()\n\n public String getId()\n\n### getLocale()\n\n public Locale getLocale()\n\n### getOnlyFacet(String name)\n\n public Facet getOnlyFacet(String name)\n\nReturns the single facet with the given name.\n\n### getOnlyField(String name)\n\n public Field getOnlyField(String name)\n\nReturns the single field with the given name.\n\n### getRank()\n\n public int getRank()\n\nReturns the rank of this document. A document's rank is used to\ndetermine the default order in which documents are returned by\nsearch, if no sorting or scoring is specified.\n\n### hashCode()\n\n public int hashCode()\n\n**Overrides** \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)\n\n### toString()\n\n public String toString()\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)"]]