Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#inhmethods)

# PutDocumentsRequest.Builder

*** ** * ** ***

` public static final class PutDocumentsRequest.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.appsearch.PutDocumentsRequest.Builder |

<br />

*** ** * ** ***

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

## Summary

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

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#addGenericDocuments(android.app.appsearch.GenericDocument[])(https://developer.android.com/reference/android/app/appsearch/GenericDocument documents) ` Adds one or more `https://developer.android.com/reference/android/app/appsearch/GenericDocument` objects to the request. |
| ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#addGenericDocuments(java.util.Collection<?%20extends%20android.app.appsearch.GenericDocument>)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/android/app/appsearch/GenericDocument> documents) ` Adds a collection of `https://developer.android.com/reference/android/app/appsearch/GenericDocument` objects to the request. |
| ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#addTakenActionGenericDocuments(java.util.Collection<?%20extends%20android.app.appsearch.GenericDocument>)(https://developer.android.com/reference/java/util/Collection<? extends https://developer.android.com/reference/android/app/appsearch/GenericDocument> takenActionGenericDocuments) ` Adds a collection of `https://developer.android.com/reference/android/app/appsearch/GenericDocument` objects containing taken action metrics to the request. |
| ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#addTakenActionGenericDocuments(android.app.appsearch.GenericDocument[])(https://developer.android.com/reference/android/app/appsearch/GenericDocument takenActionGenericDocuments) ` Adds one or more `https://developer.android.com/reference/android/app/appsearch/GenericDocument` objects containing taken action metrics to the request. |
| ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest` | ` https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#build()() ` Creates a new `https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest` object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### Builder

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Builder ()
```

<br />

<br />

## Public methods

### addGenericDocuments

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PutDocumentsRequest.Builder addGenericDocuments (GenericDocument... documents)
```

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

<br />

| Parameters ||
|---|---|
| `documents` | `GenericDocument`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | This value cannot be `null`. <br /> |

### addGenericDocuments

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PutDocumentsRequest.Builder addGenericDocuments (Collection<? extends GenericDocument> documents)
```

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

<br />

| Parameters ||
|---|---|
| `documents` | `Collection`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | This value cannot be `null`. <br /> |

### addTakenActionGenericDocuments

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [T Extensions 13](https://developer.android.com/sdkExtensions)

```
public PutDocumentsRequest.Builder addTakenActionGenericDocuments (Collection<? extends GenericDocument> takenActionGenericDocuments)
```

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

<br />

| Parameters ||
|---|---|
| `takenActionGenericDocuments` | `Collection`: a collection of `https://developer.android.com/reference/android/app/appsearch/GenericDocument` objects containing taken action metric fields. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | This value cannot be `null`. <br /> |

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

**See also:**

- `https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder#addTakenActionGenericDocuments(android.app.appsearch.GenericDocument[])`

### addTakenActionGenericDocuments

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [T Extensions 13](https://developer.android.com/sdkExtensions)

```
public PutDocumentsRequest.Builder addTakenActionGenericDocuments (GenericDocument... takenActionGenericDocuments)
```

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

It is recommended to use taken action document classes in Jetpack library to construct taken action documents.

The document creation timestamp of the `https://developer.android.com/reference/android/app/appsearch/GenericDocument` should be set to the actual action timestamp via `https://developer.android.com/reference/android/app/appsearch/GenericDocument.Builder#setCreationTimestampMillis(long)`.

Clients should report search and click actions together sorted by `https://developer.android.com/reference/android/app/appsearch/GenericDocument#getCreationTimestampMillis()` 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\].

Different types of taken actions and metrics to be collected by AppSearch:

- Search action
  - actionType: LONG, the enum value of the action type. Requires to be `1` for search actions.

  - query: STRING, the user-entered search input (without any operators or rewriting).
  - fetchedResultCount: LONG, the number of `https://developer.android.com/reference/android/app/appsearch/SearchResult` documents fetched from AppSearch in this search action.
- Click action
  - actionType: LONG, the enum value of the action type. Requires to be `2` for click actions.

  - query: STRING, the user-entered search input (without any operators or rewriting) that yielded the `https://developer.android.com/reference/android/app/appsearch/SearchResult` on which the user took action.
  - referencedQualifiedId: STRING, the qualified id of the `https://developer.android.com/reference/android/app/appsearch/SearchResult` document that the user takes action on.

    A qualified id is a string generated by package, database, namespace, and document id. See `https://developer.android.com/reference/android/app/appsearch/util/DocumentIdUtil#createQualifiedId(java.lang.String,%20java.lang.String,%20android.app.appsearch.GenericDocument)` for more details.
  - resultRankInBlock: LONG, the rank of the `https://developer.android.com/reference/android/app/appsearch/SearchResult` document among the user-defined block.

    The client can define its own custom definition for block, for example, 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 resultRankGlobal.
  - resultRankGlobal: LONG, the global rank of the `https://developer.android.com/reference/android/app/appsearch/SearchResult` document.

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

    For example, AppSearch returns 2 pages with 10 `https://developer.android.com/reference/android/app/appsearch/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.
  - timeStayOnResultMillis: LONG, the time in milliseconds that user stays on the `https://developer.android.com/reference/android/app/appsearch/SearchResult` document after clicking it.

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/android/app/appsearch/PutDocumentsRequest.Builder#addGenericDocuments(android.app.appsearch.GenericDocument[])` API to retain the benefits of joining and using it on-device, without triggering any of the anonymized stats uploading described above.

<br />

| Parameters ||
|---|---|
| `takenActionGenericDocuments` | `GenericDocument`: one or more `https://developer.android.com/reference/android/app/appsearch/GenericDocument` objects containing taken action metric fields. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest.Builder` | This value cannot be `null`. <br /> |

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

### build

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PutDocumentsRequest build ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/appsearch/PutDocumentsRequest` | This value cannot be `null`. <br /> |

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