GenericDocument.Builder
class GenericDocument.Builder<BuilderType : GenericDocument.Builder?>
The builder class for GenericDocument.
| Parameters | |
|---|---|
<BuilderType : GenericDocument.Builder?> |
Type of subclass who extends this. |
Summary
Public constructors |
|---|
Builder(document: GenericDocument)Creates a new |
|
Creates a new |
Public functions |
|
|---|---|
GenericDocument |
build()Builds the |
BuilderType |
clearProperty(name: String)Clears the value for the property with the given name. |
BuilderType |
setCreationTimestampMillis(creationTimestampMillis: Long)Sets the creation timestamp of the |
BuilderType |
Sets the ID of this document, changing the value provided in the constructor. |
BuilderType |
setNamespace(namespace: String)Sets the app-defined namespace this document resides in, changing the value provided in the constructor. |
BuilderType |
@ExperimentalAppSearchApiSets one or multiple |
BuilderType |
setPropertyBoolean(name: String, values: BooleanArray)Sets one or multiple |
BuilderType |
setPropertyBytes(name: String, values: Array<ByteArray!>)Sets one or multiple |
BuilderType |
setPropertyDocument(name: String, values: Array<GenericDocument!>)Sets one or multiple |
BuilderType |
setPropertyDouble(name: String, values: DoubleArray)Sets one or multiple |
BuilderType |
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_EMBEDDING_PROPERTY_CONFIG)Sets one or multiple |
BuilderType |
setPropertyLong(name: String, values: LongArray)Sets one or multiple |
BuilderType |
setPropertyString(name: String, values: Array<String!>)Sets one or multiple |
BuilderType |
setSchemaType(schemaType: String)Sets the schema type of this document, changing the value provided in the constructor. |
BuilderType |
setScore(score: @IntRange(from = 0, to = Integer.MAX_VALUE) Int)Sets the score of the |
BuilderType |
setTtlMillis(ttlMillis: Long)Sets the TTL (time-to-live) of the |
Public constructors
Builder
Builder(document: GenericDocument)
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
Builder(namespace: String, id: String, schemaType: String)
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: String |
the namespace to set for the |
id: String |
the unique identifier for the |
schemaType: String |
the |
Public functions
clearProperty
fun clearProperty(name: String): BuilderType
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 | |
|---|---|
name: String |
The name of the property to clear. |
setCreationTimestampMillis
fun setCreationTimestampMillis(creationTimestampMillis: Long): BuilderType
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: Long |
a creation timestamp in milliseconds. |
setId
fun setId(id: String): BuilderType
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
fun setNamespace(namespace: String): BuilderType
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)
fun setPropertyBlobHandle(name: String, values: Array<AppSearchBlobHandle!>): BuilderType
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 | |
|---|---|
name: String |
the name associated with the |
values: Array<AppSearchBlobHandle!> |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
setPropertyBoolean
fun setPropertyBoolean(name: String, values: BooleanArray): BuilderType
Sets one or multiple boolean values for a property, replacing its previous values.
| Parameters | |
|---|---|
name: String |
the name associated with the |
values: BooleanArray |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
setPropertyBytes
fun setPropertyBytes(name: String, values: Array<ByteArray!>): BuilderType
Sets one or multiple byte[] for a property, replacing its previous values.
For large byte data and lazy retrieval, see setPropertyBlobHandle.
| Parameters | |
|---|---|
name: String |
the name associated with the |
values: Array<ByteArray!> |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in |
setPropertyDocument
fun setPropertyDocument(name: String, values: Array<GenericDocument!>): BuilderType
Sets one or multiple GenericDocument values for a property, replacing its previous values.
| Parameters | |
|---|---|
name: String |
the name associated with the |
values: Array<GenericDocument!> |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in |
setPropertyDouble
fun setPropertyDouble(name: String, values: DoubleArray): BuilderType
Sets one or multiple double values for a property, replacing its previous values.
| Parameters | |
|---|---|
name: String |
the name associated with the |
values: DoubleArray |
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)
fun setPropertyEmbedding(name: String, values: Array<EmbeddingVector!>): BuilderType
Sets one or multiple EmbeddingVector values for a property, replacing its previous values.
| Parameters | |
|---|---|
name: String |
the name associated with the |
values: Array<EmbeddingVector!> |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
setPropertyLong
fun setPropertyLong(name: String, values: LongArray): BuilderType
Sets one or multiple long values for a property, replacing its previous values.
| Parameters | |
|---|---|
name: String |
the name associated with the |
values: LongArray |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the name is empty or |
setPropertyString
fun setPropertyString(name: String, values: Array<String!>): BuilderType
Sets one or multiple String values for a property, replacing its previous values.
| Parameters | |
|---|---|
name: String |
the name associated with the |
values: Array<String!> |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in |
setSchemaType
fun setSchemaType(schemaType: String): BuilderType
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
fun setScore(score: @IntRange(from = 0, to = Integer.MAX_VALUE) Int): BuilderType
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 | |
|---|---|
score: @IntRange(from = 0, to = Integer.MAX_VALUE) Int |
any non-negative |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the score is negative. |
setTtlMillis
fun setTtlMillis(ttlMillis: Long): BuilderType
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 | |
|---|---|
ttlMillis: Long |
a non-negative duration in milliseconds. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if ttlMillis is negative. |