GenericDocument.Builder

public static class GenericDocument.Builder
extends Object

java.lang.Object
   ↳ androidx.appsearch.app.GenericDocument.Builder<BuilderType extends androidx.appsearch.app.GenericDocument.Builder>


The builder class for GenericDocument.

Summary

Public constructors

Builder(String namespace, String id, String schemaType)

Creates a new GenericDocument.Builder.

Public methods

GenericDocument build()

Builds the GenericDocument object.

BuilderType clearProperty(String name)

Clears the value for the property with the given name.

BuilderType setCreationTimestampMillis(long creationTimestampMillis)

Sets the creation timestamp of the GenericDocument, in milliseconds.

BuilderType setId(String id)

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

BuilderType setNamespace(String namespace)

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

BuilderType setPropertyBoolean(String name, boolean... values)

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

BuilderType setPropertyBytes(String name, byte... values)

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

BuilderType setPropertyDocument(String name, GenericDocument... values)

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

BuilderType setPropertyDouble(String name, double... values)

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

BuilderType setPropertyLong(String name, long... values)

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

BuilderType setPropertyString(String name, String... values)

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

BuilderType setSchemaType(String schemaType)

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

BuilderType setScore(int score)

Sets the score of the GenericDocument.

BuilderType setTtlMillis(long ttlMillis)

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

Inherited methods

Public constructors

Builder

public Builder (String namespace, 
                String id, 
                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 String: the namespace to set for the GenericDocument.

id String: the unique identifier for the GenericDocument in its namespace.

schemaType String: the AppSearchSchema type of the GenericDocument. The provided schemaType must be defined using AppSearchSession.setSchema(SetSchemaRequest) prior to inserting a document of this schemaType into the AppSearch index using AppSearchSession.put(PutDocumentsRequest). Otherwise, the document will be rejected by AppSearchSession.put(PutDocumentsRequest) with result code AppSearchResult.RESULT_NOT_FOUND.

Public methods

build

public GenericDocument build ()

Builds the GenericDocument object.

Returns
GenericDocument

clearProperty

public BuilderType clearProperty (String name)

Clears the value for the property with the given name.

Note that this method does not support property paths.

Parameters
name String: The name of the property to clear.

Returns
BuilderType

setCreationTimestampMillis

public BuilderType setCreationTimestampMillis (long creationTimestampMillis)

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.

Returns
BuilderType

setId

public BuilderType setId (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 a namespace.

Parameters
id String

Returns
BuilderType

setNamespace

public BuilderType setNamespace (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.

Parameters
namespace String

Returns
BuilderType

setPropertyBoolean

public BuilderType setPropertyBoolean (String name, 
                boolean... values)

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().

values boolean: the boolean values of the property.

Returns
BuilderType

setPropertyBytes

public BuilderType setPropertyBytes (String name, 
                byte... values)

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().

values byte: the byte[] of the property.

Returns
BuilderType

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

setPropertyDocument

public BuilderType setPropertyDocument (String name, 
                GenericDocument... values)

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().

values GenericDocument: the GenericDocument values of the property.

Returns
BuilderType

Throws
IllegalArgumentException if no values are provided, or if a passed in GenericDocument is null.

setPropertyDouble

public BuilderType setPropertyDouble (String name, 
                double... values)

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().

values double: the double values of the property.

Returns
BuilderType

setPropertyLong

public BuilderType setPropertyLong (String name, 
                long... values)

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().

values long: the long values of the property.

Returns
BuilderType

setPropertyString

public BuilderType setPropertyString (String name, 
                String... values)

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().

values String: the String values of the property.

Returns
BuilderType

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

setSchemaType

public BuilderType setSchemaType (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.setSchema(SetSchemaRequest).

Parameters
schemaType String

Returns
BuilderType

setScore

public 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 int: any non-negative int representing the document's score.

Value is 2147483647 or less.

Returns
BuilderType

setTtlMillis

public 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 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 AppSearchSession.remove(RemoveByDocumentIdRequest) is called.

Parameters
ttlMillis long: a non-negative duration in milliseconds.

Returns
BuilderType