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

```
class PutDocumentsRequest.Builder
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#addDocuments(java.lang.Object...)(documents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!>)` Adds one or more annotated `https://developer.android.com/reference/kotlin/androidx/appsearch/annotation/Document` documents to the request. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#addDocuments(java.util.Collection<?>)(documents: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<*>)` Adds a collection of annotated `https://developer.android.com/reference/kotlin/androidx/appsearch/annotation/Document` documents to the request. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#addGenericDocuments(androidx.appsearch.app.GenericDocument...)(documents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument!>)` Adds one or more `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument` objects to the request. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#addGenericDocuments(java.util.Collection<? extends androidx.appsearch.app.GenericDocument>)(documents: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument!>)` Adds a collection of `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument` objects to the request. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#addTakenActions(androidx.appsearch.usagereporting.TakenAction...)(takenActions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction!>)` Adds one or more `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` objects to the request. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#addTakenActions(java.util.Collection<? extends androidx.appsearch.usagereporting.TakenAction>)(takenActions: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction!>)` Adds a collection of `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` objects to the request. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#build()()` Creates a new `https://developer.android.com/reference/kotlin/androidx/appsearch/app/PutDocumentsRequest` object. |

## Public constructors

### Builder

Added in 1.1.0

```
Builder()
```

## Public functions

### addDocuments

```
fun addDocuments(documents: Array<Any!>): PutDocumentsRequest.Builder
```

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

| Parameters |
|---|---|
| `documents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!>` | annotated `https://developer.android.com/reference/kotlin/androidx/appsearch/annotation/Document` documents. |

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

### addDocuments

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

```
fun addDocuments(documents: (Mutable)Collection<*>): PutDocumentsRequest.Builder
```

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

| Parameters |
|---|---|
| `documents: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<*>` | annotated `https://developer.android.com/reference/kotlin/androidx/appsearch/annotation/Document` documents. |

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

### addGenericDocuments

```
fun addGenericDocuments(documents: Array<GenericDocument!>): PutDocumentsRequest.Builder
```

Adds one or more `https://developer.android.com/reference/kotlin/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)

```
fun addGenericDocuments(documents: (Mutable)Collection<GenericDocument!>): PutDocumentsRequest.Builder
```

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

### addTakenActions

```
@ExperimentalAppSearchApi
fun addTakenActions(takenActions: Array<TakenAction!>): PutDocumentsRequest.Builder
```

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

Clients can construct `https://developer.android.com/reference/kotlin/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/kotlin/androidx/appsearch/usagereporting/TakenAction` for more details.

Clients should report search and click actions together sorted by `https://developer.android.com/reference/kotlin/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/kotlin/androidx/appsearch/app/PutDocumentsRequest.Builder#addDocuments(java.lang.Object...)` API with `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `takenActions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction!>` | one or more `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` objects. |

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

### addTakenActions

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

```
@ExperimentalAppSearchApi
fun addTakenActions(takenActions: (Mutable)Collection<TakenAction!>): PutDocumentsRequest.Builder
```

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

| Parameters |
|---|---|
| `takenActions: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction!>` | a collection of `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` objects. |

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
fun build(): PutDocumentsRequest
```

Creates a new `https://developer.android.com/reference/kotlin/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. |