Client class for AppSearch. An instance of this class can be created using AppSearch
Provides a connection to all AppSearch databases the querying application has been granted
access to.
Public Method Summary
abstract Task<AppSearchBatchResult<String, GenericDocument>> |
getByDocumentId(String
targetPackageName, String
databaseName,
GetByDocumentIdRequest request)
Retrieves
GenericDocument
documents, belonging to the specified package name and database name and
identified by the namespace and ids in the request, from the GlobalSearchClient
database.
|
abstract Task<GetSchemaResponse> |
getSchema(String
targetPackageName, String
databaseName)
Retrieves the collection of schemas most recently successfully provided to
AppSearchClient.setSchema(SetSchemaRequest, String) for any types
belonging to the requested package and database that the caller has been
granted access to.
|
abstract Task<Void> |
reportSystemUsage(ReportSystemUsageRequest
request)
Reports that a particular document has been used from a system surface.
|
abstract SearchResults |
search(String
queryExpression, SearchSpec
searchSpec)
Retrieves documents from all AppSearch databases that the querying application
has access to.
|
Public Methods
public abstract Task<AppSearchBatchResult<String, GenericDocument>> getByDocumentId (String targetPackageName, String databaseName, GetByDocumentIdRequest request)
Retrieves GenericDocument
documents, belonging to the specified package name and database name and identified by
the namespace and ids in the request, from the GlobalSearchClient
database.
If the package or database doesn't exist or if the calling package doesn't have
access, the gets will be handled as failures in an AppSearchBatchResult
object in the result.
Parameters
targetPackageName | the name of the package to get from |
---|---|
databaseName | the name of the database to get from |
request | a request containing a namespace and IDs to get documents for. |
Returns
- a
AppSearchBatchResult
. The keys of it are the input IDs. The values are the returnedGenericDocument
s on success, or a failedAppSearchResult
otherwise. IDs that are not found will return a failedAppSearchResult
with a result code ofAppSearchResult.RESULT_NOT_FOUND
. If an unexpected internal error occurs in the AppSearch service,BatchResultCallback.onSystemError(Throwable)
will be invoked with aThrowable
.
public abstract Task<GetSchemaResponse> getSchema (String targetPackageName, String databaseName)
Retrieves the collection of schemas most recently successfully provided to
AppSearchClient.setSchema(SetSchemaRequest, String)
for any types belonging
to the requested package and database that the caller has been granted access to.
If the requested package/database combination does not exist or the caller has not been granted access to it, then an empty GetSchemaResponse will be returned.
Parameters
targetPackageName | the package that owns the requested AppSearchSchema
instances. |
---|---|
databaseName | the database that owns the requested AppSearchSchema
instances. |
Returns
- The pending
GetSchemaResponse
containing the schemas that the caller has access to or an empty GetSchemaResponse if the request package and database does not exist, has not set a schema or contains no schemas that are accessible to the caller.
public abstract Task<Void> reportSystemUsage (ReportSystemUsageRequest request)
Reports that a particular document has been used from a system surface.
See
AppSearchClient.reportUsage(ReportUsageRequest, String)
for a general
description of document usage, as well as an API that can be used by the app
itself.
Usage reported via this method is accounted separately from usage reported via
AppSearchClient.reportUsage(ReportUsageRequest, String)
and may be accessed
using the constants
SearchSpec.RANKING_STRATEGY_SYSTEM_USAGE_COUNT
and
SearchSpec.RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP
.
Parameters
request | The usage reporting request. |
---|
public abstract SearchResults search (String queryExpression, SearchSpec searchSpec)
Retrieves documents from all AppSearch databases that the querying application has access to.
Applications can be granted access to documents by specifying
SetSchemaRequest.Builder.setSchemaTypeVisibilityForPackage(String, boolean,
PackageIdentifier)
when building a schema.
Document access can also be granted to system UIs by specifying
SetSchemaRequest.Builder.setSchemaTypeDisplayedBySystem(String, boolean)
when building a schema.
See
AppSearchClient.search(String, SearchSpec, String)
for a detailed
explanation on forming a query string.
This method is lightweight. The heavy work will be done in SearchResults.getNextPage()
.
Parameters
queryExpression | query string to search. |
---|---|
searchSpec | spec for setting document filters, adding projection, setting term match type, etc. |
Returns
- a
SearchResults
object for retrieved matched documents.