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 |
|---|
Builder(@NonNull GenericDocument document)Creates a new |
|
Creates a new |
Public methods |
|
|---|---|
@NonNull GenericDocument |
build()Builds the |
@NonNull BuilderType |
clearProperty(@NonNull String name)Clears the value for the property with the given name. |
@NonNull BuilderType |
setCreationTimestampMillis(long creationTimestampMillis)Sets the creation timestamp of the |
@NonNull BuilderType |
Sets the ID of this document, changing the value provided in the constructor. |
@NonNull BuilderType |
setNamespace(@NonNull String namespace)Sets the app-defined namespace this document resides in, changing the value provided in the constructor. |
@NonNull BuilderType |
@ExperimentalAppSearchApiSets one or multiple |
@NonNull BuilderType |
setPropertyBoolean(@NonNull String name, @NonNull boolean[] values)Sets one or multiple |
@NonNull BuilderType |
setPropertyBytes(@NonNull String name, @NonNull byte[][] values)Sets one or multiple |
@NonNull BuilderType |
setPropertyDocument(Sets one or multiple |
@NonNull BuilderType |
setPropertyDouble(@NonNull String name, @NonNull double[] values)Sets one or multiple |
@NonNull BuilderType |
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_EMBEDDING_PROPERTY_CONFIG)Sets one or multiple |
@NonNull BuilderType |
setPropertyLong(@NonNull String name, @NonNull long[] values)Sets one or multiple |
@NonNull BuilderType |
setPropertyString(@NonNull String name, @NonNull String[] values)Sets one or multiple |
@NonNull BuilderType |
setSchemaType(@NonNull String schemaType)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 |
@NonNull BuilderType |
setTtlMillis(long ttlMillis)Sets the TTL (time-to-live) of the |
Public constructors
Builder
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
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 |
@NonNull String id |
the unique identifier for the |
@NonNull String schemaType |
the |
Public methods
clearProperty
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.
setCreationTimestampMillis
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
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
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 |
@NonNull AppSearchBlobHandle[] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
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 |
@NonNull boolean[] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
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 |
@NonNull byte[][] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in |
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 |
@NonNull GenericDocument[] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in |
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 |
@NonNull double[] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
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 |
@NonNull EmbeddingVector[] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
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 |
@NonNull long[] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
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 |
@NonNull String[] values |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in |
setSchemaType
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
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 |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the score is negative. |
setTtlMillis
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. |