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
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 theGenericDocument .
|
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
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 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"
"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", "curie@example" ]
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(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 returnsnull
.
Note: If the property is an emptyGenericDocument
[]
orbyte[][]
,this method will return anull
value 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 or
null
if 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 aboolean
property by path.
See
getProperty(String)
for a detailed description of the path syntax.
Parameters
path | The path to look for. |
---|
Returns
- The first
boolean
associated with the given path or default valuefalse
if there is no such value or the value is of a different type.
public boolean[]getPropertyBooleanArray(Stringpath)
Retrieves a repeatedboolean
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
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
- The
boolean[]
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 first
byte[]
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
T
andnull
in earlier versions of Android.
Parameters
path | The path to look for. |
---|
Returns
- The
byte[][]
associated with the given path, ornull
if 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 first
GenericDocument
associated with the given path ornull
if 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
T
andnull
in earlier versions of Android.
Parameters
path | The path to look for. |
---|
Returns
- The
GenericDocument
[] associated with the given path, ornull
if no value is set or the value is of a different type.
public doublegetPropertyDouble(Stringpath)
Retrieves adouble
property by path.
See
getProperty(String)
for a detailed description of the path syntax.
Parameters
path | The path to look for. |
---|
Returns
- The first
double
associated with the given path or default value0.0
if there is no such value or the value is of a different type.
public double[]getPropertyDoubleArray(Stringpath)
Retrieves a repeateddouble
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
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
- The
double[]
associated with the given path, ornull
if no value is set or the value is of a different type.
public longgetPropertyLong(Stringpath)
Retrieves along
property by path.
See
getProperty(String)
for a detailed description of the path syntax.
Parameters
path | The path to look for. |
---|
Returns
- The first
long
associated with the given path or default value0
if 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
- The
long[]
associated with the given path, ornull
if no value is set or the value is of a different type.
publicStringgetPropertyString(Stringpath)
Retrieves aString
property by
path.
See
getProperty(String)
for a detailed description of the path syntax.
Parameters
path | The path to look for. |
---|
Returns
- The first
String
associated with the given path ornull
if there is no such value or the value is of a different type.
publicString[]getPropertyStringArray(Stringpath)
Retrieves a repeatedString
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
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
- The
String[]
associated with the given path, ornull
if 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.