public class

GenericDocument.Builder<BuilderType extends GenericDocument.Builder>

extends java.lang.Object

 java.lang.Object

↳androidx.appsearch.app.GenericDocument.Builder<BuilderType>

Subclasses:

SearchActionGenericDocument.Builder, ClickActionGenericDocument.Builder

Overview

The builder class for GenericDocument.

Summary

Constructors
publicBuilder(GenericDocument document)

Creates a new GenericDocument.Builder from the given GenericDocument.

publicBuilder(java.lang.String namespace, java.lang.String id, java.lang.String schemaType)

Creates a new GenericDocument.Builder.

Methods
public GenericDocumentbuild()

Builds the GenericDocument object.

public GenericDocument.Builder<BuilderType>clearProperty(java.lang.String name)

Clears the value for the property with the given name.

public GenericDocument.Builder<BuilderType>setCreationTimestampMillis(long creationTimestampMillis)

Sets the creation timestamp of the GenericDocument, in milliseconds.

public GenericDocument.Builder<BuilderType>setId(java.lang.String id)

Sets the ID of this document, changing the value provided in the constructor.

public GenericDocument.Builder<BuilderType>setNamespace(java.lang.String namespace)

Sets the app-defined namespace this document resides in, changing the value provided in the constructor.

public GenericDocument.Builder<BuilderType>setParentTypes(java.util.List<java.lang.String> parentTypes)

Sets the list of parent types of the GenericDocument's type.

public GenericDocument.Builder<BuilderType>setPropertyBoolean(java.lang.String name, boolean[] values[])

Sets one or multiple boolean values for a property, replacing its previous values.

public GenericDocument.Builder<BuilderType>setPropertyBytes(java.lang.String name, byte[][] values[][])

Sets one or multiple byte[] for a property, replacing its previous values.

public GenericDocument.Builder<BuilderType>setPropertyDocument(java.lang.String name, GenericDocument values[])

Sets one or multiple GenericDocument values for a property, replacing its previous values.

public GenericDocument.Builder<BuilderType>setPropertyDouble(java.lang.String name, double[] values[])

Sets one or multiple double values for a property, replacing its previous values.

public GenericDocument.Builder<BuilderType>setPropertyEmbedding(java.lang.String name, EmbeddingVector values[])

Sets one or multiple EmbeddingVector values for a property, replacing its previous values.

public GenericDocument.Builder<BuilderType>setPropertyLong(java.lang.String name, long[] values[])

Sets one or multiple long values for a property, replacing its previous values.

public GenericDocument.Builder<BuilderType>setPropertyString(java.lang.String name, java.lang.String values[])

Sets one or multiple String values for a property, replacing its previous values.

public GenericDocument.Builder<BuilderType>setSchemaType(java.lang.String schemaType)

Sets the schema type of this document, changing the value provided in the constructor.

public GenericDocument.Builder<BuilderType>setScore(int score)

Sets the score of the GenericDocument.

public GenericDocument.Builder<BuilderType>setTtlMillis(long ttlMillis)

Sets the TTL (time-to-live) of the GenericDocument, in milliseconds.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(java.lang.String namespace, java.lang.String id, java.lang.String schemaType)

Creates a new GenericDocument.Builder.

Document IDs are unique within a namespace.

The number of namespaces per app should be kept small for efficiency reasons.

Parameters:

namespace: the namespace to set for the GenericDocument.
id: the unique identifier for the GenericDocument in its namespace.
schemaType: the AppSearchSchema type of the GenericDocument. The provided schemaType must be defined using AppSearchSession.setSchemaAsync(SetSchemaRequest) prior to inserting a document of this schemaType into the AppSearch index using AppSearchSession.putAsync(PutDocumentsRequest). Otherwise, the document will be rejected by AppSearchSession.putAsync(PutDocumentsRequest) with result code AppSearchResult.RESULT_NOT_FOUND.

public Builder(GenericDocument document)

Creates a new GenericDocument.Builder from the given GenericDocument.

The GenericDocument is deep copied, that is, it changes to a new GenericDocument returned by this function and will NOT affect the original GenericDocument.

Methods

public GenericDocument.Builder<BuilderType> setNamespace(java.lang.String namespace)

Sets the app-defined namespace this document resides in, changing the value provided in the constructor. No special values are reserved or understood by the infrastructure.

Document IDs are unique within a namespace.

The number of namespaces per app should be kept small for efficiency reasons.

public GenericDocument.Builder<BuilderType> setId(java.lang.String id)

Sets the ID of this document, changing the value provided in the constructor. No special values are reserved or understood by the infrastructure.

Document IDs are unique within the combination of package, database, and namespace.

Setting a document with a duplicate id will overwrite the original document with the new document, enforcing uniqueness within the above constraint.

public GenericDocument.Builder<BuilderType> setSchemaType(java.lang.String schemaType)

Sets the schema type of this document, changing the value provided in the constructor.

To successfully index a document, the schema type must match the name of an AppSearchSchema object previously provided to AppSearchSession.setSchemaAsync(SetSchemaRequest).

public GenericDocument.Builder<BuilderType> setParentTypes(java.util.List<java.lang.String> parentTypes)

Sets the list of parent types of the GenericDocument's type.

Child types must appear before parent types in the list.

public GenericDocument.Builder<BuilderType> setScore(int score)

Sets the score of the GenericDocument.

The score is a query-independent measure of the document's quality, relative to other GenericDocument objects of the same AppSearchSchema type.

Results may be sorted by score using SearchSpec.Builder.setRankingStrategy(int). Documents with higher scores are considered better than documents with lower scores.

Any non-negative integer can be used a score. By default, scores are set to 0.

Parameters:

score: any non-negative int representing the document's score.

public GenericDocument.Builder<BuilderType> setCreationTimestampMillis(long creationTimestampMillis)

Sets the creation timestamp of the GenericDocument, in milliseconds.

This should be set using a value obtained from the currentTimeMillis time base.

If this method is not called, this will be set to the time the object is built.

Parameters:

creationTimestampMillis: a creation timestamp in milliseconds.

public GenericDocument.Builder<BuilderType> setTtlMillis(long ttlMillis)

Sets the TTL (time-to-live) of the GenericDocument, in milliseconds.

The TTL is measured against GenericDocument.getCreationTimestampMillis(). At the timestamp of creationTimestampMillis + ttlMillis, measured in the currentTimeMillis time base, the document will be auto-deleted.

The default value is 0, which means the document is permanent and won't be auto-deleted until the app is uninstalled or AppSearchSession.removeAsync(RemoveByDocumentIdRequest) is called.

Parameters:

ttlMillis: a non-negative duration in milliseconds.

public GenericDocument.Builder<BuilderType> setPropertyString(java.lang.String name, java.lang.String values[])

Sets one or multiple String values for a property, replacing its previous values.

Parameters:

name: the name associated with the values. Must match the name for this property as given in AppSearchSchema.PropertyConfig.getName().
values: the String values of the property.

public GenericDocument.Builder<BuilderType> setPropertyBoolean(java.lang.String name, boolean[] values[])

Sets one or multiple boolean values for a property, replacing its previous values.

Parameters:

name: the name associated with the values. Must match the name for this property as given in AppSearchSchema.PropertyConfig.getName().
values: the boolean values of the property.

public GenericDocument.Builder<BuilderType> setPropertyLong(java.lang.String name, long[] values[])

Sets one or multiple long values for a property, replacing its previous values.

Parameters:

name: the name associated with the values. Must match the name for this property as given in AppSearchSchema.PropertyConfig.getName().
values: the long values of the property.

public GenericDocument.Builder<BuilderType> setPropertyDouble(java.lang.String name, double[] values[])

Sets one or multiple double values for a property, replacing its previous values.

Parameters:

name: the name associated with the values. Must match the name for this property as given in AppSearchSchema.PropertyConfig.getName().
values: the double values of the property.

public GenericDocument.Builder<BuilderType> setPropertyBytes(java.lang.String name, byte[][] values[][])

Sets one or multiple byte[] for a property, replacing its previous values.

Parameters:

name: the name associated with the values. Must match the name for this property as given in AppSearchSchema.PropertyConfig.getName().
values: the byte[] of the property.

public GenericDocument.Builder<BuilderType> setPropertyDocument(java.lang.String name, GenericDocument values[])

Sets one or multiple GenericDocument values for a property, replacing its previous values.

Parameters:

name: the name associated with the values. Must match the name for this property as given in AppSearchSchema.PropertyConfig.getName().
values: the GenericDocument values of the property.

public GenericDocument.Builder<BuilderType> setPropertyEmbedding(java.lang.String name, EmbeddingVector values[])

Sets one or multiple EmbeddingVector values for a property, replacing its previous values.

Parameters:

name: the name associated with the values. Must match the name for this property as given in AppSearchSchema.PropertyConfig.getName().
values: the EmbeddingVector values of the property.

public GenericDocument.Builder<BuilderType> clearProperty(java.lang.String name)

Clears the value for the property with the given name.

Note that this method does not support property paths.

You should check for the existence of the property in GenericDocument.getPropertyNames() if you need to make sure the property being cleared actually exists.

If the string passed is an invalid or nonexistent property, no error message or behavior will be observed.

Parameters:

name: The name of the property to clear.

public GenericDocument build()

Builds the GenericDocument object.