GlobalSearchSession


public interface GlobalSearchSession extends ReadOnlyGlobalSearchSession, Closeable


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

In addition to the querying methods available in ReadOnlyGlobalSearchSession, this interface may support write operations such as reportSystemUsageAsync.

All implementations of this interface must be thread safe.

See also
AppSearchSession

Summary

Public methods

abstract void

Closes the GlobalSearchSession.

default @NonNull ListenableFuture<OpenBlobForReadResponse>
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_BLOB_HANDLE)
openBlobForReadAsync(@NonNull Set<AppSearchBlobHandle> handles)

Opens a batch of AppSearch Blobs for reading.

abstract @NonNull ListenableFuture<Void>

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

Inherited methods

From androidx.appsearch.app.ReadOnlyGlobalSearchSession
abstract @NonNull ListenableFuture<AppSearchBatchResult<StringGenericDocument>>
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.GLOBAL_SEARCH_SESSION_GET_BY_ID)
getByDocumentIdAsync(
    @NonNull String packageName,
    @NonNull String databaseName,
    @NonNull 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 GlobalSearchSession database.

abstract @NonNull Features

Returns the Features to check for the availability of certain features for this session.

abstract @NonNull ListenableFuture<GetSchemaResponse>
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.GLOBAL_SEARCH_SESSION_GET_SCHEMA)
getSchemaAsync(@NonNull String packageName, @NonNull String databaseName)

Retrieves the collection of schemas most recently successfully provided to setSchemaAsync for any types belonging to the requested package and database that the caller has been granted access to.

abstract void
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.GLOBAL_SEARCH_SESSION_REGISTER_OBSERVER_CALLBACK)
registerObserverCallback(
    @NonNull String targetPackageName,
    @NonNull ObserverSpec spec,
    @NonNull Executor executor,
    @NonNull ObserverCallback observer
)

Adds an ObserverCallback to monitor changes within the databases owned by targetPackageName if they match the given androidx.appsearch.observer.ObserverSpec.

abstract @NonNull SearchResults
search(@NonNull String queryExpression, @NonNull SearchSpec searchSpec)

Retrieves documents from all AppSearch databases that the querying application has access to.

abstract void
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.GLOBAL_SEARCH_SESSION_REGISTER_OBSERVER_CALLBACK)
unregisterObserverCallback(
    @NonNull String targetPackageName,
    @NonNull ObserverCallback observer
)

Removes previously registered ObserverCallback instances from the system.

Public methods

close

Added in 1.1.0
abstract void close()

Closes the GlobalSearchSession.

openBlobForReadAsync

Added in 1.1.0
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_BLOB_HANDLE)
default @NonNull ListenableFuture<OpenBlobForReadResponseopenBlobForReadAsync(@NonNull Set<AppSearchBlobHandle> handles)

Opens a batch of AppSearch Blobs for reading.

See openBlobForReadAsync for a general description when a blob is open for read.

The returned OpenBlobForReadResponse must be closed after use to avoid resource leaks. Failing to close it will result in system file descriptor exhaustion.

Parameters
@NonNull Set<AppSearchBlobHandle> handles

The AppSearchBlobHandles that identifies the blobs.

Returns
@NonNull ListenableFuture<OpenBlobForReadResponse>

a response containing the readable file descriptors.

reportSystemUsageAsync

Added in 1.1.0
abstract @NonNull ListenableFuture<VoidreportSystemUsageAsync(@NonNull ReportSystemUsageRequest request)

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

See reportUsageAsync 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 reportUsageAsync and may be accessed using the constants RANKING_STRATEGY_SYSTEM_USAGE_COUNT and RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP.

Returns
@NonNull ListenableFuture<Void>

The pending result of performing this operation which resolves to null on success. The pending result will be completed with an androidx.appsearch.exceptions.AppSearchException with a code of RESULT_SECURITY_ERROR if this API is invoked by an app which is not part of the system.