# GlobalSearchSession

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/app/GlobalSearchSession.java+class:androidx.appsearch.app.GlobalSearchSession) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
interface GlobalSearchSession : ReadOnlyGlobalSearchSession, Closeable
```

<br />

*** ** * ** ***

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

In addition to the querying methods available in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession`, this interface may support write operations such as `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GlobalSearchSession#reportSystemUsageAsync(androidx.appsearch.app.ReportSystemUsageRequest)`.

All implementations of this interface must be thread safe.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession` |   |

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GlobalSearchSession#close()()` Closes the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GlobalSearchSession`. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/OpenBlobForReadResponse!>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.SCHEMA_BLOB_HANDLE) https://developer.android.com/reference/kotlin/androidx/appsearch/app/GlobalSearchSession#openBlobForReadAsync(java.util.Set<androidx.appsearch.app.AppSearchBlobHandle>)(handles: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchBlobHandle!>)` Opens a batch of AppSearch Blobs for reading. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GlobalSearchSession#reportSystemUsageAsync(androidx.appsearch.app.ReportSystemUsageRequest)(request: https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReportSystemUsageRequest)` Reports that a particular document has been used from a system surface. |

### Inherited functions

From [androidx.appsearch.app.ReadOnlyGlobalSearchSession](https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession) `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchBatchResult<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument!>!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_GET_BY_ID)
https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession#getByDocumentIdAsync(java.lang.String,java.lang.String,androidx.appsearch.app.GetByDocumentIdRequest)(
packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html,
databaseName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html,
request: https://developer.android.com/reference/kotlin/androidx/appsearch/app/GetByDocumentIdRequest
)`

Retrieves `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument` documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GlobalSearchSession` database.
`https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features` `https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession#getFeatures()()`

Returns the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features` to check for the availability of certain features for this session.
`https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/GetSchemaResponse!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_GET_SCHEMA)
https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession#getSchemaAsync(java.lang.String,java.lang.String)(packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, databaseName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`

Retrieves the collection of schemas most recently successfully provided to `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession#setSchemaAsync(androidx.appsearch.app.SetSchemaRequest)` for any types belonging to the requested package and database that the caller has been granted access to.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_REGISTER_OBSERVER_CALLBACK)
https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession#registerObserverCallback(java.lang.String,androidx.appsearch.observer.ObserverSpec,java.util.concurrent.Executor,androidx.appsearch.observer.ObserverCallback)(
targetPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html,
spec: https://developer.android.com/reference/kotlin/androidx/appsearch/observer/ObserverSpec,
executor: https://developer.android.com/reference/java/util/concurrent/Executor.html,
observer: https://developer.android.com/reference/kotlin/androidx/appsearch/observer/ObserverCallback
)`

Adds an `https://developer.android.com/reference/kotlin/androidx/appsearch/observer/ObserverCallback` to monitor changes within the databases owned by `targetPackageName` if they match the given `https://developer.android.com/reference/kotlin/androidx/appsearch/observer/ObserverSpec`.
`https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResults` `https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession#search(java.lang.String,androidx.appsearch.app.SearchSpec)(queryExpression: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, searchSpec: https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec)`

Retrieves documents from all AppSearch databases that the querying application has access to.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_REGISTER_OBSERVER_CALLBACK)
https://developer.android.com/reference/kotlin/androidx/appsearch/app/ReadOnlyGlobalSearchSession#unregisterObserverCallback(java.lang.String,androidx.appsearch.observer.ObserverCallback)(
targetPackageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html,
observer: https://developer.android.com/reference/kotlin/androidx/appsearch/observer/ObserverCallback
)`

Removes previously registered `https://developer.android.com/reference/kotlin/androidx/appsearch/observer/ObserverCallback` instances from the system.

## Public functions

### close

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun close(): Unit
```

Closes the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GlobalSearchSession`.

### openBlobForReadAsync

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_BLOB_HANDLE)
fun openBlobForReadAsync(handles: (Mutable)Set<AppSearchBlobHandle!>): ListenableFuture<OpenBlobForReadResponse!>
```

Opens a batch of AppSearch Blobs for reading.

See `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession#openBlobForReadAsync(java.util.Set<androidx.appsearch.app.AppSearchBlobHandle>)` for a general description when a blob is open for read.

The returned `https://developer.android.com/reference/kotlin/androidx/appsearch/app/OpenBlobForReadResponse` must be closed after use to avoid resource leaks. Failing to close it will result in system file descriptor exhaustion.

| Parameters |
|---|---|
| `handles: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchBlobHandle!>` | The `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchBlobHandle`s that identifies the blobs. |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/OpenBlobForReadResponse!>` | a response containing the readable file descriptors. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument.Builder#setPropertyBlobHandle(java.lang.String,androidx.appsearch.app.AppSearchBlobHandle...)` |   |

### reportSystemUsageAsync

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun reportSystemUsageAsync(request: ReportSystemUsageRequest): ListenableFuture<Void!>
```

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

See `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession#reportUsageAsync(androidx.appsearch.app.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 `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession#reportUsageAsync(androidx.appsearch.app.ReportUsageRequest)` and may be accessed using the constants `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_SYSTEM_USAGE_COUNT()` and `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP()`.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html!>` | The pending result of performing this operation which resolves to `null` on success. The pending result will be completed with an `https://developer.android.com/reference/kotlin/androidx/appsearch/exceptions/AppSearchException` with a code of `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchResult#RESULT_SECURITY_ERROR()` if this API is invoked by an app which is not part of the system. |