# 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
public class SearchAction extends TakenAction
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.appsearch.usagereporting.TakenAction](https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction) ||
|   | ↳ | [androidx.appsearch.usagereporting.SearchAction](https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction) |

*** ** * ** ***

`https://developer.android.com/reference/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/androidx/appsearch/usagereporting/SearchAction` is reported together with `https://developer.android.com/reference/androidx/appsearch/usagereporting/ClickAction`, since the user clicks on `https://developer.android.com/reference/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/androidx/appsearch/app/SetSchemaRequest.Builder#addDocumentClasses(java.lang.Class<?>...)`.

Since `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction` is an AppSearch document, the client can handle deletion via `https://developer.android.com/reference/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/androidx/appsearch/annotation/Document.BuilderProducer public final class https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.Builder extends https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.BuilderBase<https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.Builder>` Builder for `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction`. |
| `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi public class https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.BuilderBase<T extends https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.BuilderBase<T>> extends https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction.BuilderBase<T>` Builder for `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction`. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction#SearchAction(androidx.appsearch.usagereporting.SearchAction.BuilderBase<?>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.BuilderBase<@https://developer.android.com/reference/androidx/annotation/NonNull ?> builder)` Constructs a `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction` from a `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.BuilderBase`. |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction#getFetchedResultCount()()` Returns total number of results fetched from AppSearch by the client in this `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction#getQuery()()` Returns the user-entered search input (without any operators or rewriting). |

### Inherited methods

From [androidx.appsearch.usagereporting.TakenAction](https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction) `long` `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction#getActionTimestampMillis()()`

Returns the timestamp when the user took the action, in milliseconds since Unix epoch.
`int` `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi
https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction#getActionType()()`

Returns the action type of the `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction`.
`long` `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction#getDocumentTtlMillis()()`

Returns the time-to-live (TTL) of the `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` document as a duration in milliseconds.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction#getId()()`

Returns the unique identifier of the `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction`.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction#getNamespace()()`

Returns the namespace of the `https://developer.android.com/reference/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
public SearchAction(@NonNull SearchAction.BuilderBase<@NonNull ?> builder)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction.BuilderBase<@https://developer.android.com/reference/androidx/annotation/NonNull ?> builder` | The builder to construct the `https://developer.android.com/reference/androidx/appsearch/usagereporting/SearchAction` from. |

## Public methods

### getFetchedResultCount

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

```
public int getFetchedResultCount()
```

Returns total number of results fetched from AppSearch by the client in this `https://developer.android.com/reference/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)

```
public @Nullable String getQuery()
```

Returns the user-entered search input (without any operators or rewriting).