# SearchAction

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

*** ** * ** ***


```
@Document(name = "builtin:SearchAction")
@ExperimentalAppSearchApi
class SearchAction : 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.SearchAction](https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction) |

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction` is a built-in AppSearch document type that contains different metrics.

- Clients can report the user's search actions.
- Usually `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction` is reported together with `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction`, since the user clicks on `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` documents after searching.

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<?>...)`.

Since `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction` 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/SearchAction.Builder : https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction.BuilderBase<https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction.Builder!>` Builder for `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction`. |
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi class https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction.BuilderBase<T : https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction.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/SearchAction`. |

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

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction#getFetchedResultCount()()` Returns total number of results fetched from AppSearch by the client in this `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction#getQuery()()` Returns the user-entered search input (without any operators or rewriting). |

### 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

### SearchAction

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

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

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

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

## Public functions

### getFetchedResultCount

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

```
fun getFetchedResultCount(): Int
```

Returns total number of results fetched from AppSearch by the client in this `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction`.

If unset, then it will be set to -1 to mark invalid.

### 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).