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/AppSearchSchema.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#inhmethods)

# AppSearchSchema.Builder

*** ** * ** ***


`
public
static
final

class
AppSearchSchema.Builder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

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

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#Builder(android.app.appsearch.AppSearchSchema)(https://developer.android.com/reference/android/app/appsearch/AppSearchSchema schema) ` Creates a new `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` from the given `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema`. |
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#Builder(java.lang.String)(https://developer.android.com/reference/java/lang/String schemaType) ` Creates a new `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder`. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` | ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#addParentType(java.lang.String)(https://developer.android.com/reference/java/lang/String parentSchemaType) ` Adds a parent type to the schema type for polymorphism, so that the schema type will be considered as a subtype of `parentSchemaType`. |
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` | ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#addProperty(android.app.appsearch.AppSearchSchema.PropertyConfig)(https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.PropertyConfig propertyConfig) ` Adds a property to the schema type. |
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema` | ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#build()() ` Constructs a new `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema` from the contents of this builder. |
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` | ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#clearParentTypes()() ` Clears all parent types added through `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#addParentType(java.lang.String)` from the schema type. |
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` | ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#clearProperties()() ` Clears all properties added through `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#addProperty(android.app.appsearch.AppSearchSchema.PropertyConfig)` from the schema type. |
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` | ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#setDescription(java.lang.String)(https://developer.android.com/reference/java/lang/String description) ` Sets a natural language description of this schema type. |
| ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` | ` https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#setSchemaType(java.lang.String)(https://developer.android.com/reference/java/lang/String schemaType) ` Sets the schema type name. |

| ### 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 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [T Extensions 17](https://developer.android.com/sdkExtensions)

```
public Builder (AppSearchSchema schema)
```

Creates a new `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder` from the given `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema`.

<br />

| Parameters ||
|---|---|
| `schema` | `AppSearchSchema`: This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (String schemaType)
```

Creates a new `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder`.

<br />

| Parameters ||
|---|---|
| `schemaType` | `String`: This value cannot be `null`. <br /> |

## Public methods

### addParentType

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

```
public AppSearchSchema.Builder addParentType (String parentSchemaType)
```

Adds a parent type to the schema type for polymorphism, so that the schema type will be
considered as a subtype of `parentSchemaType`.

Subtype relations are automatically considered transitive, so callers are only
required to provide direct parents. Specifically, if T1 \<: T2 and T2 \<: T3 are
known, then T1 \<: T3 will be inferred automatically, where \<: is the subtype
symbol.

Polymorphism is currently supported in the following ways:

- Search filters on a parent type will automatically be extended to the child types as well. For example, if Artist \<: Person, then a search with a filter on type Person (by calling `https://developer.android.com/reference/android/app/appsearch/SearchSpec.Builder#addFilterSchemas(java.lang.String[])`) will also include documents of type Artist in the search result.
- In the projection API, the property paths to project specified for a parent type will automatically be extended to the child types as well. If both a parent type and one of its child type are specified in the projection API, the parent type's paths will be merged into the child's. For more details on projection, see `https://developer.android.com/reference/android/app/appsearch/SearchSpec.Builder#addProjection(java.lang.String,%20java.util.Collection<java.lang.String>)`.
- A document property defined as type U is allowed to be set with a document of type T, as long as T \<: U, but note that index will only be based on the defined type, which is U. For example, consider a document of type "Company" with a repeated "employees" field of type "Person". We can add employees of either type "Person" or type "Artist" or both to this property, as long as "Artist" is a subtype of "Person". However, the index of the "employees" property will be based on what's defined in "Person", even for an added document of type "Artist".

Subtypes must meet the following requirements. A violation of the requirements will
cause `https://developer.android.com/reference/android/app/appsearch/AppSearchSession#setSchema(android.app.appsearch.SetSchemaRequest,%20java.util.concurrent.Executor,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<android.app.appsearch.SetSchemaResponse>>)` to throw an `https://developer.android.com/reference/android/app/appsearch/exceptions/AppSearchException` with the
result code of `https://developer.android.com/reference/android/app/appsearch/AppSearchResult#RESULT_INVALID_ARGUMENT`. Consider a type Artist
and a type Person, and Artist claims to be a subtype of Person, then:

- Every property in Person must have a corresponding property in Artist with the same name.
- Every non-document property in Person must have the same type as the type of the corresponding property in Artist. For example, if "age" is an integer property in Person, then "age" must also be an integer property in Artist, instead of a string.
- The schema type of every document property in Artist must be a subtype of the schema type of the corresponding document property in Person, if such a property exists in Person. For example, if "awards" is a document property of type Award in Person, then the type of the "awards" property in Artist must be a subtype of Award, say ArtAward. Note that every type is a subtype of itself.
- Every property in Artist must have a cardinality stricter than or equal to the cardinality of the corresponding property in Person, if such a property exists in Person. For example, if "awards" is a property in Person of cardinality OPTIONAL, then the cardinality of the "awards" property in Artist can only be REQUIRED or OPTIONAL. Rule: REQUIRED \< OPTIONAL \< REPEATED.
- There are no other enforcements on the corresponding properties in Artist, such as index type, tokenizer type, etc. These settings can be safely overridden.

A type can be defined to have multiple parents, but it must be compatible with each of
its parents based on the above rules. For example, if LocalBusiness is defined as a
subtype of both Place and Organization, then the compatibility of LocalBusiness with
Place and the compatibility of LocalBusiness with Organization will both be checked.

<br />

| Parameters ||
|---|---|
| `parentSchemaType` | `String`: This value cannot be `null`. <br /> |

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

### addProperty

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

```
public AppSearchSchema.Builder addProperty (AppSearchSchema.PropertyConfig propertyConfig)
```

Adds a property to the schema type.

<br />

| Parameters ||
|---|---|
| `propertyConfig` | `AppSearchSchema.PropertyConfig`: This value cannot be `null`. <br /> |

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

### build

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

```
public AppSearchSchema build ()
```

Constructs a new `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema` from the contents of this builder.

<br />

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

### clearParentTypes

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

```
public AppSearchSchema.Builder clearParentTypes ()
```

Clears all parent types added through `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#addParentType(java.lang.String)` from the schema
type.

<br />

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

### clearProperties

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

```
public AppSearchSchema.Builder clearProperties ()
```

Clears all properties added through `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder#addProperty(android.app.appsearch.AppSearchSchema.PropertyConfig)` from the schema
type.

<br />

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

### setDescription

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)  
Also in [T Extensions 18](https://developer.android.com/sdkExtensions)

```
public AppSearchSchema.Builder setDescription (String description)
```

Sets a natural language description of this schema type.

For more details about the description field, see `https://developer.android.com/reference/android/app/appsearch/AppSearchSchema#getDescription()`.

<br />

| Parameters ||
|---|---|
| `description` | `String`: This value cannot be `null`. <br /> |

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

### setSchemaType

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

```
public AppSearchSchema.Builder setSchemaType (String schemaType)
```

Sets the schema type name.

<br />

| Parameters ||
|---|---|
| `schemaType` | `String`: This value cannot be `null`. <br /> |

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