Class Document.Builder (2.0.0)

public static class Document.Builder

A builder of documents. This is not thread-safe.

Inheritance

java.lang.Object > Document.Builder

Constructors

Builder()

protected Builder()

Constructs a builder for a document.

Methods

addFacet(Facet facet)

public Document.Builder addFacet(Facet facet)

Adds a Facet to this builder.

Parameter
NameDescription
facetFacet

the facet to add

Returns
TypeDescription
Document.Builder

this builder

addField(Field field)

public Document.Builder addField(Field field)

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.

Parameter
NameDescription
fieldField

the field to add

Returns
TypeDescription
Document.Builder

this builder

addField(Field.Builder builder)

public Document.Builder addField(Field.Builder builder)

Adds the field builder to the document builder. Allows multiple fields with the same name.

Parameter
NameDescription
builderField.Builder

the builder of the field to add

Returns
TypeDescription
Document.Builder

this document builder

build()

public Document build()

Builds a valid document. The builder must have set a valid document id, and have a non-empty set of valid fields.

Returns
TypeDescription
Document

the document built by this builder

setId(String documentId)

public Document.Builder setId(String documentId)

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.

Parameter
NameDescription
documentIdString

the unique id for the document to be built

Returns
TypeDescription
Document.Builder

this builder

setLocale(Locale locale)

public Document.Builder setLocale(Locale locale)

Sets the Locale the document is written in.

Parameter
NameDescription
localeLocale

the Locale the document is written in

Returns
TypeDescription
Document.Builder

this document builder

setRank(int rank)

public Document.Builder setRank(int rank)

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.

Parameter
NameDescription
rankint

the rank of this document

Returns
TypeDescription
Document.Builder

this builder