GenericDocument.Builder


public class GenericDocument.Builder<BuilderType extends GenericDocument.Builder>


The builder class for GenericDocument.

Parameters
<BuilderType extends GenericDocument.Builder>

Type of subclass who extends this.

Summary

Public constructors

Creates a new GenericDocument.Builder from the given GenericDocument.

Builder(
    @NonNull String namespace,
    @NonNull String id,
    @NonNull String schemaType
)

Creates a new GenericDocument.Builder.

Public methods

@NonNull GenericDocument

Builds the GenericDocument object.

@NonNull BuilderType

Clears the value for the property with the given name.

@NonNull BuilderType
setCreationTimestampMillis(long creationTimestampMillis)

Sets the creation timestamp of the GenericDocument, in milliseconds.

@NonNull BuilderType

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

@NonNull BuilderType

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

@NonNull BuilderType
@ExperimentalAppSearchApi
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.BLOB_STORAGE)
setPropertyBlobHandle(
    @NonNull String name,
    @NonNull AppSearchBlobHandle[] values
)

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

@NonNull BuilderType
setPropertyBoolean(@NonNull String name, @NonNull boolean[] values)

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

@NonNull BuilderType
setPropertyBytes(@NonNull String name, @NonNull byte[][] values)

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

@NonNull BuilderType
setPropertyDocument(
    @NonNull String name,
    @NonNull GenericDocument[] values
)

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

@NonNull BuilderType
setPropertyDouble(@NonNull String name, @NonNull double[] values)

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

@NonNull BuilderType
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_EMBEDDING_PROPERTY_CONFIG)
setPropertyEmbedding(
    @NonNull String name,
    @NonNull EmbeddingVector[] values
)

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

@NonNull BuilderType
setPropertyLong(@NonNull String name, @NonNull long[] values)

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

@NonNull BuilderType
setPropertyString(@NonNull String name, @NonNull String[] values)

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

@NonNull BuilderType

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

@NonNull BuilderType
setScore(@IntRange(from = 0, to = Integer.MAX_VALUE) int score)

Sets the score of the GenericDocument.

@NonNull BuilderType
setTtlMillis(long ttlMillis)

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

Public constructors

Builder

Added in 1.1.0-alpha07
public Builder(@NonNull 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.

Builder

Added in 1.1.0-alpha07
public Builder(
    @NonNull String namespace,
    @NonNull String id,
    @NonNull 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
@NonNull String namespace

the namespace to set for the GenericDocument.

@NonNull String id

the unique identifier for the GenericDocument in its namespace.

@NonNull String schemaType

the AppSearchSchema type of the GenericDocument. The provided schemaType must be defined using setSchemaAsync prior to inserting a document of this schemaType into the AppSearch index using putAsync. Otherwise, the document will be rejected by putAsync with result code RESULT_NOT_FOUND.

Public methods

build

Added in 1.1.0-alpha07
public @NonNull GenericDocument build()

Builds the GenericDocument object.

clearProperty

Added in 1.1.0-alpha07
public @NonNull BuilderType clearProperty(@NonNull 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 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
@NonNull String name

The name of the property to clear.

setCreationTimestampMillis

Added in 1.1.0-alpha07
public @NonNull 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
long creationTimestampMillis

a creation timestamp in milliseconds.

setId

Added in 1.1.0-alpha07
public @NonNull BuilderType setId(@NonNull 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.

setNamespace

Added in 1.1.0-alpha07
public @NonNull BuilderType setNamespace(@NonNull 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.

setPropertyBlobHandle

@ExperimentalAppSearchApi
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.BLOB_STORAGE)
public @NonNull BuilderType setPropertyBlobHandle(
    @NonNull String name,
    @NonNull AppSearchBlobHandle[] values
)

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

AppSearchBlobHandle is a pointer to a blob of data.

Store large byte via the android.os.ParcelFileDescriptor returned from openBlobForWriteAsync. Once the blob data is committed via commitBlobAsync, the blob is retrievable via openBlobForReadAsync.

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull AppSearchBlobHandle[] values

the AppSearchBlobHandle values of the property.

Throws
java.lang.IllegalArgumentException

if the name is empty or null.

setPropertyBoolean

public @NonNull BuilderType setPropertyBoolean(@NonNull String name, @NonNull boolean[] values)

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

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull boolean[] values

the boolean values of the property.

Throws
java.lang.IllegalArgumentException

if the name is empty or null.

setPropertyBytes

public @NonNull BuilderType setPropertyBytes(@NonNull String name, @NonNull byte[][] values)

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

For large byte data and lazy retrieval, see setPropertyBlobHandle.

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull byte[][] values

the byte[] of the property.

Throws
java.lang.IllegalArgumentException

if no values are provided, or if a passed in byte[] is null, or if name is empty.

setPropertyDocument

public @NonNull BuilderType setPropertyDocument(
    @NonNull String name,
    @NonNull GenericDocument[] values
)

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

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull GenericDocument[] values

the GenericDocument values of the property.

Throws
java.lang.IllegalArgumentException

if no values are provided, or if a passed in GenericDocument is null, or if name is empty.

setPropertyDouble

public @NonNull BuilderType setPropertyDouble(@NonNull String name, @NonNull double[] values)

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

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull double[] values

the double values of the property.

Throws
java.lang.IllegalArgumentException

if the name is empty or null.

setPropertyEmbedding

@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_EMBEDDING_PROPERTY_CONFIG)
public @NonNull BuilderType setPropertyEmbedding(
    @NonNull String name,
    @NonNull EmbeddingVector[] values
)

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

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull EmbeddingVector[] values

the EmbeddingVector values of the property.

Throws
java.lang.IllegalArgumentException

if the name is empty or null.

setPropertyLong

public @NonNull BuilderType setPropertyLong(@NonNull String name, @NonNull long[] values)

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

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull long[] values

the long values of the property.

Throws
java.lang.IllegalArgumentException

if the name is empty or null.

setPropertyString

public @NonNull BuilderType setPropertyString(@NonNull String name, @NonNull String[] values)

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

Parameters
@NonNull String name

the name associated with the values. Must match the name for this property as given in getName.

@NonNull String[] values

the String values of the property.

Throws
java.lang.IllegalArgumentException

if no values are provided, or if a passed in String is null or "".

setSchemaType

Added in 1.1.0-alpha07
public @NonNull BuilderType setSchemaType(@NonNull 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 setSchemaAsync.

setScore

Added in 1.1.0-alpha07
public @NonNull BuilderType setScore(@IntRange(from = 0, to = Integer.MAX_VALUE) 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 setRankingStrategy. 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
@IntRange(from = 0, to = Integer.MAX_VALUE) int score

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

Throws
java.lang.IllegalArgumentException

if the score is negative.

setTtlMillis

Added in 1.1.0-alpha07
public @NonNull BuilderType setTtlMillis(long ttlMillis)

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

The TTL is measured against 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 removeAsync is called.

Parameters
long ttlMillis

a non-negative duration in milliseconds.

Throws
java.lang.IllegalArgumentException

if ttlMillis is negative.