AI-generated Key Takeaways
-
GenericDocument represents a document unit containing structured data conforming to its AppSearchSchema type.
-
Each document is uniquely identified by a namespace and a String ID within that namespace.
-
Documents are constructed using the GenericDocument.Builder.
-
GenericDocument provides methods to retrieve properties of various types by path, including nested and repeated properties.
-
Key properties include creation timestamp, ID, namespace, schema type, score, and time-to-live (TTL).
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.
Nested Class Summary
| class | GenericDocument.Builder<BuilderType extends Builder> | The builder class for GenericDocument. |
|
Protected Constructor Summary
Public Method Summary
| boolean | |
| long |
getCreationTimestampMillis()
Returns the creation timestamp of the
GenericDocument,
in milliseconds.
|
| String |
getId()
Returns the unique identifier of the
GenericDocument.
|
| static int |
getMaxIndexedProperties()
The maximum number of indexed properties a document can have.
|
| String |
getNamespace()
Returns the namespace of the
GenericDocument.
|
| Object | |
| boolean | |
| boolean[] | |
| byte[] | |
| byte[][] | |
| GenericDocument | |
| GenericDocument[] | |
| double | |
| double[] | |
| long | |
| long[] | |
| Set<String> |
getPropertyNames()
Returns the names of all properties defined in this document.
|
| String | |
| String[] | |
| String |
getSchemaType()
Returns the
AppSearchSchema
type of the GenericDocument.
|
| int |
getScore()
Returns the score of the
GenericDocument.
|
| long |
getTtlMillis()
Returns the TTL (time-to-live) of the
GenericDocument,
in milliseconds.
|
| int |
hashCode()
|
| String |
toString()
|
Inherited Method Summary
Protected Constructors
protected GenericDocument (GenericDocument document)
Creates a new GenericDocument
from an existing instance.
This method should be only used by constructor of a subclass.
Public Methods
public boolean equals (Object other)
public long getCreationTimestampMillis ()
Returns the creation timestamp of the GenericDocument,
in milliseconds.
The value is in the System.currentTimeMillis()
time base.
public String getId ()
Returns the unique identifier of the GenericDocument.
public static int getMaxIndexedProperties ()
The maximum number of indexed properties a document can have.
Indexed properties are properties which are strings where the
AppSearchSchema.StringPropertyConfig.getIndexingType() value is anything
other than
AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_NONE, as well as long
properties where the
AppSearchSchema.LongPropertyConfig.getIndexingType() value is
AppSearchSchema.LongPropertyConfig.INDEXING_TYPE_RANGE.
public String getNamespace ()
Returns the namespace of the GenericDocument.
public Object getProperty (String path)
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 aStringarray with one element"to"returns the two nested documents containing contact information as aGenericDocumentarray with two elements"to[1]"returns the second nested document containing Marie Curie's contact information as aGenericDocumentarray with one element"to[1].email"returns"curie@example.com""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.com", "curie@example.com"]as aStringarray 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#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 | The path to look for. |
|---|
Returns
- The entry with the given path as an object or
nullif there is no such path. The returned object will be one of the following types:String[],long[],double[],boolean[],byte[][],GenericDocument[].
public boolean getPropertyBoolean (String path)
Retrieves a boolean property by path.
See
getProperty(String) for a detailed description of the path syntax.
Parameters
| path | The path to look for. |
|---|
Returns
- The first
booleanassociated with the given path or default valuefalseif there is no such value or the value is of a different type.
public boolean[] getPropertyBooleanArray (String path)
Retrieves a repeated boolean property 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
returns null.
If it has been set via
GenericDocument.Builder.setPropertyBoolean(String, boolean...) to an empty
boolean[], this method returns an empty boolean[].
Parameters
| path | The path to look for. |
|---|
Returns
- The
boolean[]associated with the given path, ornullif no value is set or the value is of a different type.
public byte[] getPropertyBytes (String path)
Retrieves a byte[] property by path.
See
getProperty(String) for a detailed description of the path syntax.
Parameters
| path | The path to look for. |
|---|
Returns
- The first
byte[]associated with the given path ornullif there is no such value or the value is of a different type.
public byte[][] getPropertyBytesArray (String path)
Retrieves a byte[][] 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
returns null.
If it has been set via
GenericDocument.Builder.setPropertyBytes(String, byte[]...) to an empty
byte[][], this method returns an empty byte[][] starting in
Android
T and null in earlier versions of Android.
Parameters
| path | The path to look for. |
|---|
Returns
- The
byte[][]associated with the given path, ornullif no value is set or the value is of a different type.
public GenericDocument getPropertyDocument (String path)
Retrieves a GenericDocument
property by path.
See
getProperty(String) for a detailed description of the path syntax.
Parameters
| path | The path to look for. |
|---|
Returns
- The first
GenericDocumentassociated with the given path ornullif there is no such value or the value is of a different type.
public GenericDocument[] getPropertyDocumentArray (String path)
Retrieves a repeated GenericDocument
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 returns null.
If it has been set via
GenericDocument.Builder.setPropertyDocument(String, GenericDocument...) to
an empty GenericDocument[], this method returns an empty
GenericDocument[] starting in Android
T and null in earlier versions of Android.
Parameters
| path | The path to look for. |
|---|
Returns
- The
GenericDocument[] associated with the given path, ornullif no value is set or the value is of a different type.
public double getPropertyDouble (String path)
Retrieves a double property by path.
See
getProperty(String) for a detailed description of the path syntax.
Parameters
| path | The path to look for. |
|---|
Returns
- The first
doubleassociated with the given path or default value0.0if there is no such value or the value is of a different type.
public double[] getPropertyDoubleArray (String path)
Retrieves a repeated double property 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
returns null.
If it has been set via
GenericDocument.Builder.setPropertyDouble(String, double...) to an empty
double[], this method returns an empty double[].
Parameters
| path | The path to look for. |
|---|
Returns
- The
double[]associated with the given path, ornullif no value is set or the value is of a different type.
public long getPropertyLong (String path)
Retrieves a long property by path.
See
getProperty(String) for a detailed description of the path syntax.
Parameters
| path | The path to look for. |
|---|
Returns
- The first
longassociated with the given path or default value0if there is no such value or the value is of a different type.
public long[] getPropertyLongArray (String path)
Retrieves a repeated long[] 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
returns null.
If it has been set via
GenericDocument.Builder.setPropertyLong(String, long...) to an empty
long[], this method returns an empty long[].
Parameters
| path | The path to look for. |
|---|
Returns
- The
long[]associated with the given path, ornullif no value is set or the value is of a different type.
public Set<String> getPropertyNames ()
Returns the names of all properties defined in this document.
public String getPropertyString (String path)
Retrieves a String property by
path.
See
getProperty(String) for a detailed description of the path syntax.
Parameters
| path | The path to look for. |
|---|
Returns
- The first
Stringassociated with the given path ornullif there is no such value or the value is of a different type.
public String[] getPropertyStringArray (String path)
Retrieves a repeated String property 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
returns null.
If it has been set via
GenericDocument.Builder.setPropertyString(String, String...) to an empty
String[], this method returns an empty String[].
Parameters
| path | The path to look for. |
|---|
Returns
- The
String[]associated with the given path, ornullif no value is set or the value is of a different type.
public String getSchemaType ()
Returns the AppSearchSchema
type of the GenericDocument.
public int getScore ()
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
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 long getTtlMillis ()
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
AppSearchClient.remove(RemoveByDocumentIdRequest, String) is called.