AppSearchSchema.Builder


class AppSearchSchema.Builder


Builder for objects.

Summary

Public constructors

Creates a new AppSearchSchema.Builder from the given AppSearchSchema.

Builder(schemaType: String)

Creates a new AppSearchSchema.Builder.

Public functions

AppSearchSchema.Builder
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_ADD_PARENT_TYPE)
addParentType(parentSchemaType: String)

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

AppSearchSchema.Builder

Adds a property to the given type.

AppSearchSchema

Constructs a new AppSearchSchema from the contents of this builder.

AppSearchSchema.Builder

Clears all parent types from the given type.

AppSearchSchema.Builder

Clears all properties from the given type.

AppSearchSchema.Builder
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_SET_DESCRIPTION)
setDescription(description: String)

Sets a natural language description of this schema type.

AppSearchSchema.Builder
setSchemaType(schemaType: String)

Sets the schema type name.

Public constructors

Builder

Added in 1.1.0-alpha06
Builder(schema: AppSearchSchema)

Creates a new AppSearchSchema.Builder from the given AppSearchSchema.

Builder

Added in 1.1.0-alpha06
Builder(schemaType: String)

Creates a new AppSearchSchema.Builder.

Public functions

addParentType

Added in 1.1.0-alpha06
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_ADD_PARENT_TYPE)
fun addParentType(parentSchemaType: String): AppSearchSchema.Builder

Adds a parent type to the given type for polymorphism, so that the given 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 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 addProjection.
  • 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 setSchemaAsync to throw an AppSearchException with the result code of 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
  • 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.

addProperty

Added in 1.1.0-alpha06
fun addProperty(propertyConfig: AppSearchSchema.PropertyConfig): AppSearchSchema.Builder

Adds a property to the given type.

build

Added in 1.1.0-alpha06
fun build(): AppSearchSchema

Constructs a new AppSearchSchema from the contents of this builder.

clearParentTypes

Added in 1.1.0-alpha06
fun clearParentTypes(): AppSearchSchema.Builder

Clears all parent types from the given type.

clearProperties

Added in 1.1.0-alpha06
fun clearProperties(): AppSearchSchema.Builder

Clears all properties from the given type.

setDescription

Added in 1.1.0-alpha06
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_SET_DESCRIPTION)
fun setDescription(description: String): AppSearchSchema.Builder

Sets a natural language description of this schema type.

For more details about the description field, see getDescription.

setSchemaType

Added in 1.1.0-alpha06
fun setSchemaType(schemaType: String): AppSearchSchema.Builder

Sets the schema type name.