GenericDocument

public classGenericDocumentextendsObject

Represents a document unit.

Documents contain structured data conforming to theirAppSearchSchema type. Each document is uniquely identified by a namespace and a String ID within that namespace.

Documents are constructed by using theGenericDocument.Builder.

Nested Class Summary

class GenericDocument.Builder<BuilderType extendsBuilder> The builder class forGenericDocument.

Protected Constructor Summary

GenericDocument(GenericDocument document)
Creates a newGenericDocument from an existing instance.

Public Method Summary

boolean
long
getCreationTimestampMillis()
Returns the creation timestamp of theGenericDocument, in milliseconds.
String
getId()
Returns the unique identifier of theGenericDocument.
static int
getMaxIndexedProperties()
The maximum number of indexed properties a document can have.
String
getNamespace()
Returns the namespace of theGenericDocument.
Object
getProperty(Stringpath)
Retrieves the property value with the given path asObject.
boolean
getPropertyBoolean(Stringpath)
Retrieves abooleanproperty by path.
boolean[]
getPropertyBooleanArray(Stringpath)
Retrieves a repeatedbooleanproperty by path.
byte[]
getPropertyBytes(Stringpath)
Retrieves abyte[]property by path.
byte[][]
getPropertyBytesArray(Stringpath)
Retrieves abyte[][]property by path.
GenericDocument
getPropertyDocument(Stringpath)
Retrieves aGenericDocument property by path.
GenericDocument[]
getPropertyDocumentArray(Stringpath)
Retrieves a repeatedGenericDocument property by path.
double
getPropertyDouble(Stringpath)
Retrieves adoubleproperty by path.
double[]
getPropertyDoubleArray(Stringpath)
Retrieves a repeateddoubleproperty by path.
long
getPropertyLong(Stringpath)
Retrieves alongproperty by path.
long[]
getPropertyLongArray(Stringpath)
Retrieves a repeatedlong[]property by path.
Set<String>
getPropertyNames()
Returns the names of all properties defined in this document.
String
getPropertyString(Stringpath)
Retrieves aString property by path.
String[]
getPropertyStringArray(Stringpath)
Retrieves a repeatedStringproperty by path.
String
int
getScore()
Returns the score of theGenericDocument.
long
getTtlMillis()
Returns the TTL (time-to-live) of theGenericDocument, in milliseconds.
int
String

Inherited Method Summary

Protected Constructors

protectedGenericDocument(GenericDocument document)

Creates a newGenericDocument from an existing instance.

This method should be only used by constructor of a subclass.

Public Methods

public booleanequals(Objectother)

public longgetCreationTimestampMillis()

Returns the creation timestamp of theGenericDocument, in milliseconds.

The value is in theSystem.currentTimeMillis() time base.

publicStringgetId()

Returns the unique identifier of theGenericDocument.

public static intgetMaxIndexedProperties()

The maximum number of indexed properties a document can have.

Indexed properties are properties which are strings where the AppSearchSchema.StringPropertyConfig.getInde xing Type()value is anything other than AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_NONE,as well as long properties where the AppSearchSchema.LongPropertyConfig.getInde xing Type()value is AppSearchSchema.LongPropertyConfig.INDEXING_TYPE_RANGE.

publicStringgetNamespace()

Returns the namespace of theGenericDocument.

publicObjectgetProperty(Stringpath)

Retrieves the property value with the given path asObject.

A path can be a simple property name, such as those returned by getPropertyNames().It may also be a dot-delimited path through the nested document hierarchy, with nestedGenericDocument properties accessed via'.'and repeated properties optionally indexed into via[n].

For example, given the followingGenericDocument:

(Message) {
from: "sender@example"
to: [{
name: "Albert Einstein"
email: "einstein@example"
}, {
name: "Marie Curie"
email: "curie@example"
}]
tags: [ "important", "inbox" ]
subject: "Hello"
}

Here are some example paths and their results:

  • "from"returns"sender@example"as aStringarray with one element
  • "to"returns the two nested documents containing contact information as aGenericDocument array with two elements
  • "to[1]"returns the second nested document containing Marie Curie's contact information as aGenericDocument array with one element
  • "to[1].email"returns"curie@example"
  • "to[100].email"returnsnullas this particular document does not have that many elements in its"to"array.
  • "to.email"aggregates emails across all nested documents that have them, returning[ "einstein@example", "curie@example" ]as a Stringarray with two elements.

If you know the expected type of the property you are retrieving, it is recommended to use one of the typed versions of this method instead, such as getPropertyString(String)or getPropertyStringArray(String).

If the property was assigned as an empty array using one of the Builder#setPropertyfunctions, this method will return an empty array. If no such property exists at all, this method returnsnull.

Note: If the property is an emptyGenericDocument[] orbyte[][],this method will return anullvalue in versions of Android prior toAndroid T.Starting in Android T it will return an empty array if the property has been set as an empty array, matching the behavior of other property types.

Parameters
path The path to look for.
Returns
  • The entry with the given path as an object ornullif there is no such path. The returned object will be one of the following types: String[],long[],double[], boolean[],byte[][],GenericDocument[].

public booleangetPropertyBoolean(Stringpath)

Retrieves abooleanproperty by path.

See getProperty(String)for a detailed description of the path syntax.

Parameters
path The path to look for.
Returns
  • The firstbooleanassociated with the given path or default value falseif there is no such value or the value is of a different type.

public boolean[]getPropertyBooleanArray(Stringpath)

Retrieves a repeatedbooleanproperty by path.

See getProperty(String)for a detailed description of the path syntax.

If the property has not been set via GenericDocument.Builder.setPropertyBoolean(String, boolean...),this method returnsnull.

If it has been set via GenericDocument.Builder.setPropertyBoolean(String, boolean...)to an empty boolean[],this method returns an emptyboolean[].

Parameters
path The path to look for.
Returns
  • Theboolean[]associated with the given path, ornull if no value is set or the value is of a different type.

public byte[]getPropertyBytes(Stringpath)

Retrieves abyte[]property by path.

See getProperty(String)for a detailed description of the path syntax.

Parameters
path The path to look for.
Returns
  • The firstbyte[]associated with the given path ornull if there is no such value or the value is of a different type.

public byte[][]getPropertyBytesArray(Stringpath)

Retrieves abyte[][]property by path.

See getProperty(String)for a detailed description of the path syntax.

If the property has not been set via GenericDocument.Builder.setPropertyBytes(String, byte[]...),this method returnsnull.

If it has been set via GenericDocument.Builder.setPropertyBytes(String, byte[]...)to an empty byte[][],this method returns an emptybyte[][]starting in Android Tandnullin earlier versions of Android.

Parameters
path The path to look for.
Returns
  • Thebyte[][]associated with the given path, ornullif no value is set or the value is of a different type.

publicGenericDocument getPropertyDocument(String path)

Retrieves aGenericDocument property by path.

See getProperty(String)for a detailed description of the path syntax.

Parameters
path The path to look for.
Returns
  • The firstGenericDocument associated with the given path ornullif there is no such value or the value is of a different type.

publicGenericDocument[] getPropertyDocumentArray(String path)

Retrieves a repeatedGenericDocument property by path.

See getProperty(String)for a detailed description of the path syntax.

If the property has not been set via GenericDocument.Builder.setPropertyDocument(String, GenericDocument...), this method returnsnull.

If it has been set via GenericDocument.Builder.setPropertyDocument(String, GenericDocument...)to an emptyGenericDocument[],this method returns an empty GenericDocument[]starting inAndroid Tandnullin earlier versions of Android.

Parameters
path The path to look for.
Returns
  • TheGenericDocument[] associated with the given path, ornullif no value is set or the value is of a different type.

public doublegetPropertyDouble(Stringpath)

Retrieves adoubleproperty by path.

See getProperty(String)for a detailed description of the path syntax.

Parameters
path The path to look for.
Returns
  • The firstdoubleassociated with the given path or default value 0.0if there is no such value or the value is of a different type.

public double[]getPropertyDoubleArray(Stringpath)

Retrieves a repeateddoubleproperty by path.

See getProperty(String)for a detailed description of the path syntax.

If the property has not been set via GenericDocument.Builder.setPropertyDouble(String, double...),this method returnsnull.

If it has been set via GenericDocument.Builder.setPropertyDouble(String, double...)to an empty double[],this method returns an emptydouble[].

Parameters
path The path to look for.
Returns
  • Thedouble[]associated with the given path, ornullif no value is set or the value is of a different type.

public longgetPropertyLong(Stringpath)

Retrieves alongproperty by path.

See getProperty(String)for a detailed description of the path syntax.

Parameters
path The path to look for.
Returns
  • The firstlongassociated with the given path or default value 0if there is no such value or the value is of a different type.

public long[]getPropertyLongArray(Stringpath)

Retrieves a repeatedlong[]property by path.

See getProperty(String)for a detailed description of the path syntax.

If the property has not been set via GenericDocument.Builder.setPropertyLong(String, long...),this method returnsnull.

If it has been set via GenericDocument.Builder.setPropertyLong(String, long...)to an empty long[],this method returns an emptylong[].

Parameters
path The path to look for.
Returns
  • Thelong[]associated with the given path, ornullif no value is set or the value is of a different type.

publicSet<String> getPropertyNames()

Returns the names of all properties defined in this document.

publicStringgetPropertyString(Stringpath)

Retrieves aStringproperty by path.

See getProperty(String)for a detailed description of the path syntax.

Parameters
path The path to look for.
Returns
  • The firstString associated with the given path ornullif there is no such value or the value is of a different type.

publicString[]getPropertyStringArray(Stringpath)

Retrieves a repeatedStringproperty by path.

See getProperty(String)for a detailed description of the path syntax.

If the property has not been set via GenericDocument.Builder.setPropertyString(String, String...),this method returnsnull.

If it has been set via GenericDocument.Builder.setPropertyString(String, String...)to an empty String[],this method returns an emptyString[].

Parameters
path The path to look for.
Returns
  • TheString[]associated with the given path, ornullif no value is set or the value is of a different type.

publicStringgetSchemaType()

Returns theAppSearchSchema type of theGenericDocument.

public intgetScore()

Returns the score of theGenericDocument.

The score is a query-independent measure of the document's quality, relative to otherGenericDocument objects of the sameAppSearchSchema 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.

public longgetTtlMillis()

Returns the TTL (time-to-live) of theGenericDocument, in milliseconds.

The TTL is measured against getCreationTimestampMillis().At the timestamp of creationTimestampMillis + ttlMillis,measured in theSystem.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 AppSearchClient.remove(RemoveByDocumentIdRequest, String)is called.

public inthashCode()

publicStringtoString()