# Print output for @column tags ?> GlobalSearchSession - Android SDK | Android Developers

Most visited

Recently visited

GlobalSearchSession

public class GlobalSearchSession
extends Object implements Closeable

java.lang.Object
   ↳ android.app.appsearch.GlobalSearchSession


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

This class is thread safe.

See also:

Summary

Public methods

void close()

Closes the GlobalSearchSession.

void reportSystemUsage(ReportSystemUsageRequest request, Executor executor, Consumer<AppSearchResult<Void>> callback)

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

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 void close ()

Closes the GlobalSearchSession. Persists all mutations, including usage reports, to disk.

reportSystemUsage

public void reportSystemUsage (ReportSystemUsageRequest request, 
                Executor executor, 
                Consumer<AppSearchResult<Void>> callback)

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

See AppSearchSession#reportUsage 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 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: The usage reporting request. This value cannot be null.

executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). To dispatch events through a shared thread pool, you can use AsyncTask#THREAD_POOL_EXECUTOR.

callback Consumer: Callback to receive errors. If the operation succeeds, the callback will be invoked with an AppSearchResult whose value is null. The callback will be invoked with an AppSearchResult of AppSearchResult#RESULT_SECURITY_ERROR if this API is invoked by an app which is not part of the system. This value cannot be null.

search

public 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 AppSearchSession#search for a detailed explanation on forming a query string.

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

Parameters
queryExpression String: query string to search. This value cannot be null.

searchSpec SearchSpec: spec for setting document filters, adding projection, setting term match type, etc. This value cannot be null.

Returns
SearchResults a SearchResults object for retrieved matched documents. This value cannot be null.