Builder
open class Builder<BuilderType : GenericDocument.Builder<GenericDocument.Builder<*>>!>
kotlin.Any | |
↳ | android.app.appsearch.GenericDocument.Builder |
The builder class for GenericDocument
.
Summary
Public constructors | |
---|---|
Creates a new |
|
Builder(document: GenericDocument) Creates a new |
Public methods | |
---|---|
open GenericDocument |
build() Builds the |
open BuilderType |
clearProperty(name: String) Clears the value for the property with the given name. |
open BuilderType |
setCreationTimestampMillis(creationTimestampMillis: Long) Sets the creation timestamp of the |
open BuilderType |
Sets the ID of this document, changing the value provided in the constructor. |
open BuilderType |
setNamespace(namespace: String) Sets the app-defined namespace this document resides in, changing the value provided in the constructor. |
open BuilderType |
setPropertyBoolean(name: String, vararg values: Boolean) Sets one or multiple |
open BuilderType |
setPropertyBytes(name: String, vararg values: ByteArray!) Sets one or multiple |
open BuilderType |
setPropertyDocument(name: String, vararg values: GenericDocument!) Sets one or multiple |
open BuilderType |
setPropertyDouble(name: String, vararg values: Double) Sets one or multiple |
open BuilderType |
setPropertyLong(name: String, vararg values: Long) Sets one or multiple |
open BuilderType |
setPropertyString(name: String, vararg values: String!) Sets one or multiple |
open BuilderType |
setSchemaType(schemaType: String) Sets the schema type of this document, changing the value provided in the constructor. |
open BuilderType |
Sets the score of the |
open BuilderType |
setTtlMillis(ttlMillis: Long) Sets the TTL (time-to-live) of the |
Public constructors
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 GenericDocument . This value cannot be null . |
id |
String: the unique identifier for the GenericDocument in its namespace. This value cannot be null . |
schemaType |
String: the AppSearchSchema type of the GenericDocument . The provided schemaType must be defined using AppSearchSession#setSchema prior to inserting a document of this schemaType into the AppSearch index using AppSearchSession#put . Otherwise, the document will be rejected by AppSearchSession#put with result code android.app.appsearch.AppSearchResult#RESULT_NOT_FOUND . This value cannot be null . |
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.
Parameters | |
---|---|
document |
GenericDocument: This value cannot be null . |
Public methods
build
open fun build(): GenericDocument
Builds the GenericDocument
object.
Return | |
---|---|
GenericDocument |
This value cannot be null . |
clearProperty
open 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. This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
setCreationTimestampMillis
open fun setCreationTimestampMillis(creationTimestampMillis: Long): BuilderType
Sets the creation timestamp of the GenericDocument
, in milliseconds.
This should be set using a value obtained from the System#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. Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. |
Return | |
---|---|
BuilderType |
This value cannot be null . |
setId
open 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.
Parameters | |
---|---|
id |
String: This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
setNamespace
open 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.
Parameters | |
---|---|
namespace |
String: This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
setPropertyBoolean
open fun setPropertyBoolean(
name: String,
vararg values: Boolean
): BuilderType
Sets one or multiple boolean
values for a property, replacing its previous values.
Parameters | |
---|---|
name |
String: the name associated with the values . Must match the name for this property as given in AppSearchSchema.PropertyConfig#getName . This value cannot be null . |
values |
Boolean: the boolean values of the property. This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the name is empty or null . |
setPropertyBytes
open fun setPropertyBytes(
name: String,
vararg values: ByteArray!
): BuilderType
Sets one or multiple byte[]
for a property, replacing its previous values.
Parameters | |
---|---|
name |
String: the name associated with the values . Must match the name for this property as given in AppSearchSchema.PropertyConfig#getName . This value cannot be null . |
values |
ByteArray!: the byte[] of the property. This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in byte[] is null , or if name is empty. |
setPropertyDocument
open fun setPropertyDocument(
name: String,
vararg values: GenericDocument!
): BuilderType
Sets one or multiple GenericDocument
values for a property, replacing its previous values.
Parameters | |
---|---|
name |
String: the name associated with the values . Must match the name for this property as given in AppSearchSchema.PropertyConfig#getName . This value cannot be null . |
values |
GenericDocument!: the GenericDocument values of the property. This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in GenericDocument is null , or if name is empty. |
setPropertyDouble
open fun setPropertyDouble(
name: String,
vararg values: Double
): BuilderType
Sets one or multiple double
values for a property, replacing its previous values.
Parameters | |
---|---|
name |
String: the name associated with the values . Must match the name for this property as given in AppSearchSchema.PropertyConfig#getName . This value cannot be null . |
values |
Double: the double values of the property. This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the name is empty or null . |
setPropertyLong
open fun setPropertyLong(
name: String,
vararg values: Long
): BuilderType
Sets one or multiple long
values for a property, replacing its previous values.
Parameters | |
---|---|
name |
String: the name associated with the values . Must match the name for this property as given in AppSearchSchema.PropertyConfig#getName . This value cannot be null . |
values |
Long: the long values of the property. This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the name is empty or null . |
setPropertyString
open fun setPropertyString(
name: String,
vararg values: String!
): BuilderType
Sets one or multiple String
values for a property, replacing its previous values.
Parameters | |
---|---|
name |
String: the name associated with the values . Must match the name for this property as given in AppSearchSchema.PropertyConfig#getName . This value cannot be null . |
values |
String!: the String values of the property. This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if no values are provided, or if a passed in String is null or "". |
setSchemaType
open 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 AppSearchSession#setSchema
.
Parameters | |
---|---|
schemaType |
String: This value cannot be null . |
Return | |
---|---|
BuilderType |
This value cannot be null . |
setScore
open fun setScore(score: 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 android.app.appsearch.SearchSpec.Builder#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 |
Int: any non-negative int representing the document's score. Value is between 0 and Integer.MAX_VALUE inclusive |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the score is negative. |
setTtlMillis
open 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 java.lang.System#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 android.app.appsearch.AppSearchSession#remove is called.
Parameters | |
---|---|
ttlMillis |
Long: a non-negative duration in milliseconds. |
Return | |
---|---|
BuilderType |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if ttlMillis is negative. |