# ImpressionAction

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/usagereporting/ImpressionAction.java+class:androidx.appsearch.usagereporting.ImpressionAction) 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.JOIN_SPEC_AND_QUALIFIED_ID)
@Document(name = "builtin:ImpressionAction")
@ExperimentalAppSearchApi
class ImpressionAction : TakenAction
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.appsearch.usagereporting.TakenAction](https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction) ||
|   | ↳ | [androidx.appsearch.usagereporting.ImpressionAction](https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction) |

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction` is a built-in AppSearch document type that contains different metrics. Clients can report the user's impression actions on a `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document.

- Different from `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction`, impression action means the user showed impression and took actions (other than click) on the result document, such as hovering the result preview.
- If the user clicked on the result document, then it is recommended to use `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction` instead. Still the caller can decide to report both `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction` and `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction` for a single result document at the same time, depending on their use cases for the action signals (e.g. boost ranking).

In order to use this document type, the client must explicitly set this schema type via `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SetSchemaRequest.Builder#addDocumentClasses(java.lang.Class<?>...)`.

Impression actions can be used as signals to boost ranking via `https://developer.android.com/reference/kotlin/androidx/appsearch/app/JoinSpec` API in future search requests.

Since `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction` is an AppSearch document, the client can handle deletion via `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession#removeAsync(androidx.appsearch.app.RemoveByDocumentIdRequest)` or document time-to-live (TTL). The default TTL is 60 days.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/annotation/Document.BuilderProducer class https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.Builder : https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.BuilderBase<https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.Builder!>` Builder for `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction`. |
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi class https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.BuilderBase<T : https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.BuilderBase<T!>?> : https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction.BuilderBase<T!>` Builder for `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction`. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction#ImpressionAction(androidx.appsearch.usagereporting.ImpressionAction.BuilderBase<?>)(builder: https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.BuilderBase<*>)` Constructs an `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction` from a `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.BuilderBase`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction#getQuery()()` Returns the user-entered search input (without any operators or rewriting) that yielded the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` which impressed the user. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction#getReferencedQualifiedId()()` Returns the qualified id of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document that impressed the user. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction#getResultRankGlobal()()` Returns the global rank of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction#getResultRankInBlock()()` Returns the rank of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document among the user-defined block. |

### Inherited functions

From [androidx.appsearch.usagereporting.TakenAction](https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction#getActionTimestampMillis()()`

Returns the timestamp when the user took the action, in milliseconds since Unix epoch.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi
https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction#getActionType()()`

Returns the action type of the `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction`.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction#getDocumentTtlMillis()()`

Returns the time-to-live (TTL) of the `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` document as a duration in milliseconds.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction#getId()()`

Returns the unique identifier of the `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction`.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction#getNamespace()()`

Returns the namespace of the `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction`.

## Public constructors

### ImpressionAction

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

```
@ExperimentalAppSearchApi
ImpressionAction(builder: ImpressionAction.BuilderBase<*>)
```

Constructs an `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction` from a `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.BuilderBase`.

| Parameters |
|---|---|
| `builder: https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction.BuilderBase<*>` | The builder to construct the `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction` from. |

## Public functions

### getQuery

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

```
fun getQuery(): String?
```

Returns the user-entered search input (without any operators or rewriting) that yielded the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` which impressed the user.

### getReferencedQualifiedId

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

```
fun getReferencedQualifiedId(): String?
```

Returns the qualified id of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document that impressed the user.

A qualified id is a string generated by package, database, namespace, and document id. See `https://developer.android.com/reference/kotlin/androidx/appsearch/util/DocumentIdUtil#createQualifiedId(java.lang.String,java.lang.String,java.lang.String,java.lang.String)` for more details.

### getResultRankGlobal

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

```
fun getResultRankGlobal(): Int
```

Returns the global rank of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document.

Global rank reflects the order of `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` documents returned by AppSearch.

For example, AppSearch returns 2 pages with 10 `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` documents for each page. Then the global ranks of them will be 1 to 10 for the first page, and 11 to 20 for the second page.

If unset, then the global rank of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document will be set to -1 to mark invalid.

### getResultRankInBlock

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

```
fun getResultRankInBlock(): Int
```

Returns the rank of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document among the user-defined block.

The client can define its own custom definition for block, e.g. corpus name, group, etc.

For example, a client defines the block as corpus, and AppSearch returns 5 documents with corpus = \["corpus1", "corpus1", "corpus2", "corpus3", "corpus2"\]. Then the block ranks of them = \[1, 2, 1, 1, 2\].

If the client is not presenting the results in multiple blocks, they should set this value to match `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ImpressionAction#getResultRankGlobal()`.

If unset, then the block rank of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` document will be set to -1 to mark invalid.