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
Name Description
facet Facet

the facet to add

Returns
Type Description
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
Name Description
field Field

the field to add

Returns
Type Description
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
Name Description
builder Field.Builder

the builder of the field to add

Returns
Type Description
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
Type Description
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
Name Description
documentId String

the unique id for the document to be built

Returns
Type Description
Document.Builder

this builder

setLocale(Locale locale)

public Document.Builder setLocale(Locale locale)

Sets the Locale the document is written in.

Parameter
Name Description
locale Locale

the Locale the document is written in

Returns
Type Description
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
Name Description
rank int

the rank of this document

Returns
Type Description
Document.Builder

this builder