Adds the field to the builder. Allows multiple fields with the same name, except
that documents may only have one date and one number field for a name.
Set the document id to a unique valid value. A valid document id must
be a printable ASCII string of between 1 and
DocumentChecker#MAXIMUM_DOCUMENT_ID_LENGTH characters, and
also not start with '!' which is reserved. If no document id is
provided, then the search service will provide one when the document
is indexed.
Sets the rank of this document, which determines the order of documents
returned by search, if no sorting or scoring is given. If it is not
specified, then the number of seconds since 2011/1/1 will be used.
[[["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-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eDocument.Builder\u003c/code\u003e class is used to create documents and is not safe for concurrent use in multiple threads.\u003c/p\u003e\n"],["\u003cp\u003eYou can add multiple fields with the same name to a document, except for date and number fields which are limited to one per name.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ebuild()\u003c/code\u003e method is used to create a document after a valid document ID and a non-empty set of fields are added.\u003c/p\u003e\n"],["\u003cp\u003eYou can set a custom document ID using \u003ccode\u003esetId()\u003c/code\u003e or allow the search service to assign one automatically upon indexing.\u003c/p\u003e\n"],["\u003cp\u003eYou can define a document's rank through \u003ccode\u003esetRank()\u003c/code\u003e to influence search result ordering or it will automatically default to the seconds since 2011/1/1.\u003c/p\u003e\n"]]],[],null,["# Class Document.Builder (2.0.0)\n\n public static class Document.Builder\n\nA builder of documents. This is not thread-safe. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e Document.Builder \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\nConstructors\n------------\n\n### Builder()\n\n protected Builder()\n\nConstructs a builder for a document.\n\nMethods\n-------\n\n### addFacet(Facet facet)\n\n public Document.Builder addFacet(Facet facet)\n\nAdds a [Facet](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Facet) to this builder.\n\n### addField(Field field)\n\n public Document.Builder addField(Field field)\n\nAdds the field to the builder. Allows multiple fields with the same name, except\nthat documents may only have one date and one number field for a name.\n\n### addField(Field.Builder builder)\n\n public Document.Builder addField(Field.Builder builder)\n\nAdds the field builder to the document builder. Allows multiple\nfields with the same name.\n\n### build()\n\n public Document build()\n\nBuilds a valid document. The builder must have set a valid document\nid, and have a non-empty set of valid fields.\n\n### setId(String documentId)\n\n public Document.Builder setId(String documentId)\n\nSet the document id to a unique valid value. A valid document id must\nbe a printable ASCII string of between 1 and\nDocumentChecker#MAXIMUM_DOCUMENT_ID_LENGTH characters, and\nalso not start with '!' which is reserved. If no document id is\nprovided, then the search service will provide one when the document\nis indexed.\n\n### setLocale(Locale locale)\n\n public Document.Builder setLocale(Locale locale)\n\nSets the [Locale](https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html) the document is written in.\n\n### setRank(int rank)\n\n public Document.Builder setRank(int rank)\n\nSets the rank of this document, which determines the order of documents\nreturned by search, if no sorting or scoring is given. If it is not\nspecified, then the number of seconds since 2011/1/1 will be used."]]