AppSearchSession

public interface AppSearchSession
implements Closeable

androidx.appsearch.app.AppSearchSession


Provides a connection to a single AppSearch database.

An AppSearchSession instance provides access to database operations such as setting a schema, adding documents, and searching.

Instances of this interface are usually obtained from a storage implementation, e.g. LocalStorage.createSearchSession() or PlatformStorage.createSearchSession().

All implementations of this interface must be thread safe.

Summary

Public methods

abstract void close()

Closes the AppSearchSession to persist all schema and document updates, additions, and deletes to disk.

abstract ListenableFuture<AppSearchBatchResult<String, GenericDocument>> getByDocumentId(GetByDocumentIdRequest request)

Gets GenericDocument objects by document IDs in a namespace from the AppSearchSession database.

abstract ListenableFuture<Set<String>> getNamespaces()

Retrieves the set of all namespaces in the current database with at least one document.

abstract ListenableFuture<GetSchemaResponse> getSchema()

Retrieves the schema most recently successfully provided to setSchema(SetSchemaRequest).

abstract ListenableFuture<StorageInfo> getStorageInfo()

Gets the storage info for this AppSearchSession database.

abstract ListenableFuture<AppSearchBatchResult<String, Void>> put(PutDocumentsRequest request)

Indexes documents into the AppSearchSession database.

abstract ListenableFuture<Void> remove(String queryExpression, SearchSpec searchSpec)

Removes GenericDocuments from the index by Query.

abstract ListenableFuture<AppSearchBatchResult<String, Void>> remove(RemoveByDocumentIdRequest request)

Removes GenericDocument objects by document IDs in a namespace from the AppSearchSession database.

abstract ListenableFuture<Void> reportUsage(ReportUsageRequest request)

Reports usage of a particular document by namespace and ID.

abstract ListenableFuture<Void> requestFlush()

Flush all schema and document updates, additions, and deletes to disk if possible.

abstract SearchResults search(String queryExpression, SearchSpec searchSpec)

Retrieves documents from the open AppSearchSession that match a given query string and type of search provided.

abstract ListenableFuture<SetSchemaResponse> setSchema(SetSchemaRequest request)

Sets the schema that represents the organizational structure of data within the AppSearch database.

Inherited methods

Public methods

close

public abstract void close ()

Closes the AppSearchSession to persist all schema and document updates, additions, and deletes to disk.

getByDocumentId

public abstract ListenableFuture<AppSearchBatchResult<String, GenericDocument>> getByDocumentId (GetByDocumentIdRequest request)

Gets GenericDocument objects by document IDs in a namespace from the AppSearchSession database.

Parameters
request GetByDocumentIdRequest: a request containing a namespace and IDs to get documents for.

Returns
ListenableFuture<AppSearchBatchResult<String, GenericDocument>> A ListenableFuture which resolves to an AppSearchBatchResult. The keys of the AppSearchBatchResult represent the input document IDs from the GetByDocumentIdRequest object. The values are either the corresponding GenericDocument object for the ID on success, or an AppSearchResult object on failure. For example, if an ID is not found, the value for that ID will be set to an AppSearchResult object with result code: AppSearchResult.RESULT_NOT_FOUND.

getNamespaces

public abstract ListenableFuture<Set<String>> getNamespaces ()

Retrieves the set of all namespaces in the current database with at least one document.

Returns
ListenableFuture<Set<String>> The pending result of performing this operation.

getSchema

public abstract ListenableFuture<GetSchemaResponse> getSchema ()

Retrieves the schema most recently successfully provided to setSchema(SetSchemaRequest).

Returns
ListenableFuture<GetSchemaResponse> The pending GetSchemaResponse of performing this operation.

getStorageInfo

public abstract ListenableFuture<StorageInfo> getStorageInfo ()

Gets the storage info for this AppSearchSession database.

This may take time proportional to the number of documents and may be inefficient to call repeatedly.

Returns
List