# PutDocumentsRequest.Builder

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

*** ** * ** ***

<br />

```
public final class PutDocumentsRequest.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest` objects.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#Builder()()` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addDocuments(java.lang.Object...)(@https://developer.android.com/reference/androidx/annotation/NonNull Object[] documents)` Adds one or more annotated `https://developer.android.com/reference/androidx/appsearch/annotation/Document` documents to the request. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addDocuments(java.util.Collection<?>)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> documents)` Adds a collection of annotated `https://developer.android.com/reference/androidx/appsearch/annotation/Document` documents to the request. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addGenericDocuments(androidx.appsearch.app.GenericDocument...)(@https://developer.android.com/reference/androidx/annotation/NonNull GenericDocument[] documents)` Adds one or more `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` objects to the request. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addGenericDocuments(java.util.Collection<? extends androidx.appsearch.app.GenericDocument>)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<https://developer.android.com/reference/androidx/appsearch/app/GenericDocument> documents)` Adds a collection of `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` objects to the request. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder` | `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addTakenActions(androidx.appsearch.usagereporting.TakenAction...)(@https://developer.android.com/reference/androidx/annotation/NonNull TakenAction[] takenActions)` Adds one or more `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` objects to the request. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder` | `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addTakenActions(java.util.Collection<? extends androidx.appsearch.usagereporting.TakenAction>)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction> takenActions)` Adds a collection of `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` objects to the request. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest` | `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#build()()` Creates a new `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest` object. |

## Public constructors

### Builder

Added in 1.1.0

```
public Builder()
```

## Public methods

### addDocuments

```
public @NonNull PutDocumentsRequest.Builder addDocuments(@NonNull Object[] documents)
```

Adds one or more annotated `https://developer.android.com/reference/androidx/appsearch/annotation/Document` documents to the request.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Object[] documents` | annotated `https://developer.android.com/reference/androidx/appsearch/annotation/Document` documents. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` | if an error occurs converting a document class into a `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`. |

### addDocuments

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

```
public @NonNull PutDocumentsRequest.Builder addDocuments(@NonNull Collection<@NonNull ?> documents)
```

Adds a collection of annotated `https://developer.android.com/reference/androidx/appsearch/annotation/Document` documents to the request.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> documents` | annotated `https://developer.android.com/reference/androidx/appsearch/annotation/Document` documents. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` | if an error occurs converting a document into a `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`. |

### addGenericDocuments

```
public @NonNull PutDocumentsRequest.Builder addGenericDocuments(@NonNull GenericDocument[] documents)
```

Adds one or more `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` objects to the request.

### addGenericDocuments

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

```
public @NonNull PutDocumentsRequest.Builder addGenericDocuments(@NonNull Collection<GenericDocument> documents)
```

Adds a collection of `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` objects to the request.

### addTakenActions

```
@ExperimentalAppSearchApi
public @NonNull PutDocumentsRequest.Builder addTakenActions(@NonNull TakenAction[] takenActions)
```

Adds one or more `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` objects to the request.

Clients can construct `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` documents to report the user's actions on search results, and these actions can be used as signals to boost result ranking in future search requests. See `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` for more details.

Clients should report search and click actions together sorted by `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction#getActionTimestampMillis()` in chronological order.

For example, if there are 2 search actions, with 1 click action associated with the first and 2 click actions associated with the second, then clients should report \[searchAction1, clickAction1, searchAction2, clickAction2, clickAction3\].

Certain anonymized information about actions reported using this API may be uploaded using statsd and may be used to improve the quality of the search algorithms. Most of the information in this class is already non-identifiable, such as durations and its position in the result set. Identifiable information which you choose to provide, such as the query string, will be anonymized using techniques like Federated Analytics to ensure only the most frequently searched terms across the whole user population are retained and available for study.

You can alternatively use the `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addDocuments(java.lang.Object...)` API with `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` document to retain the benefits of joining and using it on-device, without triggering any of the anonymized stats uploading described above.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull TakenAction[] takenActions` | one or more `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` objects. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` |   |

### addTakenActions

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

```
@ExperimentalAppSearchApi
public @NonNull PutDocumentsRequest.Builder addTakenActions(@NonNull Collection<TakenAction> takenActions)
```

Adds a collection of `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` objects to the request.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction> takenActions` | a collection of `https://developer.android.com/reference/androidx/appsearch/usagereporting/TakenAction` objects. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` |   |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest.Builder#addTakenActions(androidx.appsearch.usagereporting.TakenAction...)` |   |

### build

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

```
public @NonNull PutDocumentsRequest build()
```

Creates a new `https://developer.android.com/reference/androidx/appsearch/app/PutDocumentsRequest` object.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if there is any id collision between normal and action documents. |