EnterpriseGlobalSearchSession


@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ENTERPRISE_GLOBAL_SEARCH_SESSION)
public interface EnterpriseGlobalSearchSession


Provides a connection to all enterprise (work profile) AppSearch databases the querying application has been granted access to.

This session can be created from any user profile but will only properly return results when created from the main profile. If the user is not the main profile or an associated work profile does not exist, queries will still successfully complete but with empty results.

Schemas must be explicitly tagged enterprise and may require additional permissions to be visible from an enterprise session. Retrieved documents may also have certain fields restricted or modified unlike if they were retrieved directly from GlobalSearchSession on the work profile.

All implementations of this interface must be thread safe.

Summary

Public methods

abstract @NonNull ListenableFuture<AppSearchBatchResult<StringGenericDocument>>
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 EnterpriseGlobalSearchSession database.

abstract @NonNull Features

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

abstract @NonNull ListenableFuture<GetSchemaResponse>
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 @NonNull SearchResults
search(@NonNull String queryExpression, @NonNull SearchSpec searchSpec)

Retrieves documents from all enterprise (work profile) AppSearch databases that the querying application has access to.

Public methods

getByDocumentIdAsync

Added in 1.1.0-alpha07
abstract @NonNull ListenableFuture<AppSearchBatchResult<StringGenericDocument>> 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 EnterpriseGlobalSearchSession database. When a call is successful, the result will be returned in the successes section of the AppSearchBatchResult object in the callback. If the package doesn't exist, database doesn't exist, or if the calling package doesn't have access, these failures will be reflected as AppSearchResult objects with a RESULT_NOT_FOUND status code in the failures section of the AppSearchBatchResult object.

Parameters
@NonNull String packageName

the name of the package to get from

@NonNull String databaseName

the name of the database to get from

@NonNull GetByDocumentIdRequest request

a request containing a namespace and IDs of the documents to retrieve.

getFeatures

Added in 1.1.0-alpha07
abstract @NonNull Features getFeatures()

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

getSchemaAsync

Added in 1.1.0-alpha07
abstract @NonNull ListenableFuture<GetSchemaResponsegetSchemaAsync(@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.

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
@NonNull String packageName

the package that owns the requested AppSearchSchema instances.

@NonNull String databaseName

the database that owns the requested AppSearchSchema instances.

Returns
@NonNull ListenableFuture<GetSchemaResponse>

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.

search

Added in 1.1.0-alpha07
abstract @NonNull SearchResults search(@NonNull String queryExpression, @NonNull SearchSpec searchSpec)

Retrieves documents from all enterprise (work profile) AppSearch databases that the querying application has access to.

Applications can be granted access to documents by specifying setSchemaTypeVisibilityForPackage, or setDocumentClassVisibilityForPackage when building a schema.

Document access can also be granted to system UIs by specifying setSchemaTypeDisplayedBySystem, or setDocumentClassDisplayedBySystem when building a schema.

See search for a detailed explanation on forming a query string.

This method is lightweight. The heavy work will be done in getNextPageAsync.

Parameters
@NonNull String queryExpression

query string to search.

@NonNull SearchSpec searchSpec

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

Returns
@NonNull SearchResults

a SearchResults object for retrieved matched documents.