GlobalSearchSession

public interface GlobalSearchSession
implements Closeable

androidx.appsearch.app.GlobalSearchSession


Provides a connection to all AppSearch databases the querying application has been granted access to.

All implementations of this interface must be thread safe.

See also:

Summary

Public methods

abstract void close()

Closes the GlobalSearchSession.

abstract ListenableFuture<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.

Inherited methods

Public methods

close

public abstract void close ()

Closes the GlobalSearchSession.

reportSystemUsage

public abstract ListenableFuture<Void> reportSystemUsage (ReportSystemUsageRequest request)

Reports that a particular document has been used from a system surface.

See AppSearchSession.reportUsage(ReportUsageRequest) 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 AppSearchSession.reportUsage(ReportUsageRequest) and may be accessed using the constants SearchSpec.RANKING_STRATEGY_SYSTEM_USAGE_COUNT and SearchSpec.RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP.

Parameters
request ReportSystemUsageRequest

Returns
ListenableFuture<Void> The pending result of performing this operation which resolves to null on success. The pending result will be completed with an AppSearchException with a code of AppSearchResult.RESULT_SECURITY_ERROR if this API is invoked by an app which is not part of the system.

search

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), or SetSchemaRequest.Builder.setDocumentClassVisibilityForPackage(Class, boolean, PackageIdentifier) when building a schema.

Document access can also be granted to system UIs by specifying SetSchemaRequest.Builder.setSchemaTypeDisplayedBySystem(String, boolean), or SetSchemaRequest.Builder.setDocumentClassDisplayedBySystem(Class, boolean) when building a schema.

See AppSearchSession.search(String, SearchSpec) for a detailed explanation on forming a query string.

This method is lightweight. The heavy work will be done in SearchResults.getNextPage().

Parameters
queryExpression String: query string to search.

searchSpec SearchSpec: spec for setting document filters, adding projection, setting term match type, etc.

Returns
SearchResults a SearchResults object for retrieved matched documents.