GenericDocument
open class GenericDocument
kotlin.Any | |
↳ | android.app.appsearch.GenericDocument |
Represents a document unit.
Documents contain structured data conforming to their AppSearchSchema
type. Each document is uniquely identified by a namespace and a String ID within that namespace.
Documents are constructed by using the GenericDocument.Builder
.
Summary
Nested classes | |
---|---|
open |
The builder class for |
Protected constructors | |
---|---|
GenericDocument(document: GenericDocument) Creates a new |
Public methods | |
---|---|
open Boolean |
Indicates whether some other object is "equal to" this one. |
open Long |
Returns the creation timestamp of the |
open String |
getId() Returns the unique identifier of the |
open static Int |
The maximum number of indexed properties a document can have. |
open String |
Returns the namespace of the |
open Any? |
getProperty(path: String) Retrieves the property value with the given path as |
open Boolean |
getPropertyBoolean(path: String) Retrieves a |
open BooleanArray? |
getPropertyBooleanArray(path: String) Retrieves a repeated |
open ByteArray? |
getPropertyBytes(path: String) Retrieves a |
open Array<ByteArray!>? |
getPropertyBytesArray(path: String) Retrieves a |
open GenericDocument? |
getPropertyDocument(path: String) Retrieves a |
open Array<GenericDocument!>? |
getPropertyDocumentArray(path: String) Retrieves a repeated |
open Double |
getPropertyDouble(path: String) Retrieves a |
open DoubleArray? |
getPropertyDoubleArray(path: String) Retrieves a repeated |
open Long |
getPropertyLong(path: String) Retrieves a |
open LongArray? |
getPropertyLongArray(path: String) Retrieves a repeated |
open MutableSet<String!> |
Returns the names of all properties defined in this document. |
open String? |
getPropertyString(path: String) Retrieves a |
open Array<String!>? |
getPropertyStringArray(path: String) Retrieves a repeated |
open String |
Returns the |
open Int |
getScore() Returns the score of the |
open Long |
Returns the TTL (time-to-live) of the |
open Int |
hashCode() |
open String |
toString() Returns a string representation of the object. |
Protected constructors
GenericDocument
protected GenericDocument(document: GenericDocument)
Creates a new GenericDocument
from an existing instance.
This method should be only used by constructor of a subclass.
Parameters | |
---|---|
document |
GenericDocument: This value cannot be null . |
Public methods
equals
open fun equals(other: Any?): Boolean
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
Parameters | |
---|---|
obj |
the reference object with which to compare. |
other |
Any?: This value may be null . |
Return | |
---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
getCreationTimestampMillis
open fun getCreationTimestampMillis(): Long
Returns the creation timestamp of the GenericDocument
, in milliseconds.
The value is in the System#currentTimeMillis
time base.
Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z.
Return | |
---|---|
Long |
Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. |
getId
open fun getId(): String
Returns the unique identifier of the GenericDocument
.
Return | |
---|---|
String |
This value cannot be null . |
getMaxIndexedProperties
open static fun getMaxIndexedProperties(): Int
The maximum number of indexed properties a document can have.
Indexed properties are properties which are strings where the android.app.appsearch.AppSearchSchema.StringPropertyConfig#getIndexingType
value is anything other than android.app.appsearch.AppSearchSchema.StringPropertyConfig#INDEXING_TYPE_NONE
, as well as long properties where the AppSearchSchema.LongPropertyConfig#getIndexingType
value is android.app.appsearch.AppSearchSchema.LongPropertyConfig#INDEXING_TYPE_RANGE
.
getNamespace
open fun getNamespace(): String
Returns the namespace of the GenericDocument
.
Return | |
---|---|
String |
This value cannot be null . |
getProperty
open fun getProperty(path: String): Any?
Retrieves the property value with the given path as Object
.
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 nested GenericDocument
properties accessed via '.'
and repeated properties optionally indexed into via [n]
.
For example, given the following GenericDocument
:
(Message) { from: "sender@example.com" to: [{ name: "Albert Einstein" email: "einstein@example.com" }, { name: "Marie Curie" email: "curie@example.com" }] tags: ["important", "inbox"] subject: "Hello" }
Here are some example paths and their results:
"from"
returns"sender@example.com"
as aString
array 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.com"
"to[100].email"
returnsnull
as 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.com", "curie@example.com"]
as aString
array 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
or getPropertyStringArray
.
If the property was assigned as an empty array using one of the Builder#setProperty
functions, this method will return an empty array. If no such property exists at all, this method returns null
.
Note: If the property is an empty GenericDocument
[] or byte[][]
, this method will return a null
value in versions of Android prior to Android 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 |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
Any? |
The entry with the given path as an object or null if there is no such path. The returned object will be one of the following types: String[] , long[] , double[] , boolean[] , byte[][] , GenericDocument[] . |
getPropertyBoolean
open fun getPropertyBoolean(path: String): Boolean
Retrieves a boolean
property by path.
See getProperty
for a detailed description of the path syntax.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
Boolean |
The first boolean associated with the given path or default value false if there is no such value or the value is of a different type. |
getPropertyBooleanArray
open fun getPropertyBooleanArray(path: String): BooleanArray?
Retrieves a repeated boolean
property by path.
See getProperty
for a detailed description of the path syntax.
If the property has not been set via Builder#setPropertyBoolean
, this method returns null
.
If it has been set via Builder#setPropertyBoolean
to an empty boolean[]
, this method returns an empty boolean[]
.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
BooleanArray? |
The boolean[] associated with the given path, or null if no value is set or the value is of a different type. |
getPropertyBytes
open fun getPropertyBytes(path: String): ByteArray?
Retrieves a byte[]
property by path.
See getProperty
for a detailed description of the path syntax.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
ByteArray? |
The first byte[] associated with the given path or null if there is no such value or the value is of a different type. |
getPropertyBytesArray
open fun getPropertyBytesArray(path: String): Array<ByteArray!>?
Retrieves a byte[][]
property by path.
See getProperty
for a detailed description of the path syntax.
If the property has not been set via Builder#setPropertyBytes
, this method returns null
.
If it has been set via Builder#setPropertyBytes
to an empty byte[][]
, this method returns an empty byte[][]
starting in Android T
and null
in earlier versions of Android.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
Array<ByteArray!>? |
The byte[][] associated with the given path, or null if no value is set or the value is of a different type. |
getPropertyDocument
open fun getPropertyDocument(path: String): GenericDocument?
Retrieves a GenericDocument
property by path.
See getProperty
for a detailed description of the path syntax.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
GenericDocument? |
The first GenericDocument associated with the given path or null if there is no such value or the value is of a different type. |
getPropertyDocumentArray
open fun getPropertyDocumentArray(path: String): Array<GenericDocument!>?
Retrieves a repeated GenericDocument
property by path.
See getProperty
for a detailed description of the path syntax.
If the property has not been set via Builder#setPropertyDocument
, this method returns null
.
If it has been set via Builder#setPropertyDocument
to an empty GenericDocument[]
, this method returns an empty GenericDocument[]
starting in Android T
and null
in earlier versions of Android.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
Array<GenericDocument!>? |
The GenericDocument [] associated with the given path, or null if no value is set or the value is of a different type. |
getPropertyDouble
open fun getPropertyDouble(path: String): Double
Retrieves a double
property by path.
See getProperty
for a detailed description of the path syntax.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
Double |
The first double associated with the given path or default value 0.0 if there is no such value or the value is of a different type. |
getPropertyDoubleArray
open fun getPropertyDoubleArray(path: String): DoubleArray?
Retrieves a repeated double
property by path.
See getProperty
for a detailed description of the path syntax.
If the property has not been set via Builder#setPropertyDouble
, this method returns null
.
If it has been set via Builder#setPropertyDouble
to an empty double[]
, this method returns an empty double[]
.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
DoubleArray? |
The double[] associated with the given path, or null if no value is set or the value is of a different type. |
getPropertyLong
open fun getPropertyLong(path: String): Long
Retrieves a long
property by path.
See getProperty
for a detailed description of the path syntax.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
Long |
The first long associated with the given path or default value 0 if there is no such value or the value is of a different type. |
getPropertyLongArray
open fun getPropertyLongArray(path: String): LongArray?
Retrieves a repeated long[]
property by path.
See getProperty
for a detailed description of the path syntax.
If the property has not been set via Builder#setPropertyLong
, this method returns null
.
If it has been set via Builder#setPropertyLong
to an empty long[]
, this method returns an empty long[]
.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
LongArray? |
The long[] associated with the given path, or null if no value is set or the value is of a different type. |
getPropertyNames
open fun getPropertyNames(): MutableSet<String!>
Returns the names of all properties defined in this document.
Return | |
---|---|
MutableSet<String!> |
This value cannot be null . |
getPropertyString
open fun getPropertyString(path: String): String?
Retrieves a String
property by path.
See getProperty
for a detailed description of the path syntax.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
String? |
The first String associated with the given path or null if there is no such value or the value is of a different type. |
getPropertyStringArray
open fun getPropertyStringArray(path: String): Array<String!>?
Retrieves a repeated String
property by path.
See getProperty
for a detailed description of the path syntax.
If the property has not been set via Builder#setPropertyString
, this method returns null
.
If it has been set via Builder#setPropertyString
to an empty String[]
, this method returns an empty String[]
.
Parameters | |
---|---|
path |
String: The path to look for. This value cannot be null . |
Return | |
---|---|
Array<String!>? |
The String[] associated with the given path, or null if no value is set or the value is of a different type. |
getSchemaType
open fun getSchemaType(): String
Returns the AppSearchSchema
type of the GenericDocument
.
Return | |
---|---|
String |
This value cannot be null . |
getScore
open fun getScore(): Int
Returns 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.
getTtlMillis
open fun getTtlMillis(): Long
Returns 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 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.
hashCode
open fun hashCode(): Int
Return | |
---|---|
Int |
a hash code value for this object. |
toString
open fun toString(): String
Returns a string representation of the object.
Return | |
---|---|
String |
This value cannot be null . |