GlobalSearchClient

public interfaceGlobalSearchClientimplements HasApiKey<AppSearchOptions>

Client class for AppSearch. An instance of this class can be created usingAppSearch 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, GetByDocumentIdRequestrequest)
RetrievesGenericDocument documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from theGlobalSearchClient 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.
abstractSearchResults
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(StringtargetPackageName, StringdatabaseName, GetByDocumentIdRequest request)

RetrievesGenericDocument documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from theGlobalSearchClient 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 anAppSearchBatchResult 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

public abstract Task<GetSchemaResponse> getSchema(StringtargetPackageName, 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 requestedAppSearchSchema instances.
databaseName the database that owns the requestedAppSearchSchema instances.
Returns
  • The pendingGetSchemaResponse 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_COUNTand SearchSpec.RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP.

Parameters
request The usage reporting request.

public abstractSearchResults search(StringqueryExpression, 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 inSearchResults.getNextPage().

Parameters
queryExpression query string to search.
searchSpec spec for setting document filters, adding projection, setting term match type, etc.
Returns