# AppSearchSchema.Builder

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

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/app/appsearch/AppSearchSchema.Builder "View this page in Java")  

```
class Builder
```

|---|------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                 ||
| ↳ | [android.app.appsearch.AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#) |

Builder for[objects](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema).

## Summary

|                                                                                                                                                                                                                                                             Public constructors                                                                                                                                                                                                                                                              ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#Builder(android.app.appsearch.AppSearchSchema))`(`schema:` `[AppSearchSchema](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema)`)` Creates a new[AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#)from the given[AppSearchSchema](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema). |
| [Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#Builder(kotlin.String))`(`schemaType:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Creates a new[AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#).                                                                                                                                                                 |

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

## Public constructors

### Builder

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

```
Builder(schema: AppSearchSchema)
```

Creates a new[AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#)from the given[AppSearchSchema](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema).

|                                                                  Parameters                                                                   ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------|
| `schema` | [AppSearchSchema](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema):This value cannot be`null`. |

### Builder

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

```
Builder(schemaType: String)
```

Creates a new[AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#).

|                                                         Parameters                                                         ||
|--------------|--------------------------------------------------------------------------------------------------------------|
| `schemaType` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. |

## Public methods

### addParentType

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

```
fun addParentType(parentSchemaType: String): AppSearchSchema.Builder
```

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 android.app.appsearch.SearchSpec.Builder#addFilterSchemas) 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[android.app.appsearch.SearchSpec.Builder#addProjection](https://developer.android.com/reference/kotlin/android/app/appsearch/SearchSpec.Builder#addProjection(kotlin.String,%20kotlin.collections.MutableCollection)).
- 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[AppSearchSession.setSchema](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSession#setSchema(android.app.appsearch.SetSchemaRequest,%20java.util.concurrent.Executor,%20java.util.concurrent.Executor,%20java.util.function.Consumer))to throw an[AppSearchException](https://developer.android.com/reference/kotlin/android/app/appsearch/exceptions/AppSearchException)with the result code of[AppSearchResult.RESULT_INVALID_ARGUMENT](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchResult#RESULT_INVALID_ARGUMENT:kotlin.Int). 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.

|                                                            Parameters                                                            ||
|--------------------|--------------------------------------------------------------------------------------------------------------|
| `parentSchemaType` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. |

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#) | This value cannot be`null`. |

### addProperty

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

```
fun addProperty(propertyConfig: AppSearchSchema.PropertyConfig): AppSearchSchema.Builder
```

Adds a property to the schema type.

|                                                                                     Parameters                                                                                      ||
|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `propertyConfig` | [AppSearchSchema.PropertyConfig](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.PropertyConfig):This value cannot be`null`. |

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#) | This value cannot be`null`. |

### build

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

```
fun build(): AppSearchSchema
```

Constructs a new[AppSearchSchema](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema)from the contents of this builder.

|                                                                Return                                                                ||
|---------------------------------------------------------------------------------------------------------|-----------------------------|
| [AppSearchSchema](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema) | This value cannot be`null`. |

### clearParentTypes

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

```
fun clearParentTypes(): AppSearchSchema.Builder
```

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

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#) | This value cannot be`null`. |

### clearProperties

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

```
fun clearProperties(): AppSearchSchema.Builder
```

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

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#) | This value cannot be`null`. |

### setDescription

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

```
fun setDescription(description: String): AppSearchSchema.Builder
```

Sets a natural language description of this schema type.

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

|                                                         Parameters                                                          ||
|---------------|--------------------------------------------------------------------------------------------------------------|
| `description` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. |

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#) | This value cannot be`null`. |

### setSchemaType

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

```
fun setSchemaType(schemaType: String): AppSearchSchema.Builder
```

Sets the schema type name.

|                                                         Parameters                                                         ||
|--------------|--------------------------------------------------------------------------------------------------------------|
| `schemaType` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. |

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AppSearchSchema.Builder](https://developer.android.com/reference/kotlin/android/app/appsearch/AppSearchSchema.Builder#) | This value cannot be`null`. |