Document

public abstract @interface Document
implements Annotation

androidx.appsearch.annotation.Document


Marks a class as an entity known to AppSearch containing a data record.

Each field annotated with one of the Property annotations will become an AppSearch searchable property. Fields annotated with other annotations included here (like @Id) will have the special behaviour described in that annotation. All other members (those which do not have any of these annotations) will be ignored by AppSearch and will not be persisted or set.

Each AppSearch annotated field must meet at least one the following conditions:

  1. There must be a getter named get<Fieldname> in the class (with package-private visibility or greater), or
  2. The field itself must have package-private visibility or greater.

The field must also meet at least one of the following conditions:

  1. There must be a setter named set<FieldName>(arg) in the class (with package-private visibility or greater), or
  2. There must be a setter named fieldname(arg) in the class (with package-private visibility or greater), or
  3. The field itself must be mutable (non-final) and have package-private visibility or greater, or
  4. There must be a constructor that accepts all fields not meeting condition 1. and 2. as parameters. That constructor must have package-private visibility or greater. It may also accept fields that do meet conditions 1 and 2, in which case the constructor will be used to populate those fields instead of methods 1 and 2.

Fields may be named according to any of the following conventions:

  • exampleName
  • mExampleName
  • _exampleName
  • exampleName_

In all of the above cases, the default property name will be "exampleName", the allowed getters are getExampleName() or exampleName(), the allowed setters are setExampleName(arg) or exampleName(arg), and the expected constructor parameter for the field is "exampleName".

The class must also have exactly one member annotated with @Id.

Properties contain the document's data. They may be indexed or non-indexed (the default). Only indexed properties can be searched for in queries. There is a limit of GenericDocument.getMaxIndexedProperties() indexed properties in one document.

Summary

Nested classes

@interface Document.BooleanProperty

Configures a boolean member field of a class as a property known to AppSearch. 

@interface Document.BytesProperty

Configures a byte array member field of a class as a property known to AppSearch. 

@interface Document.CreationTimestampMillis

Marks a member field of a document as the document's creation timestamp. 

@interface Document.DocumentProperty

Configures a member field of a class as a property known to AppSearch. 

@interface Document.DoubleProperty

Configures a double-precision decimal number field of a class as a property known to AppSearch. 

@interface Document.Id

Marks a member field of a document as the document's unique identifier (ID). 

@interface Document.Int64Property

Configures a 64-bit integer field of a class as a property known to AppSearch. 

@interface Document.Namespace

Marks a member field of a document as the document's namespace. 

@interface Document.Score

Marks a member field of a document as the document's query-independent score. 

@interface Document.StringProperty

Configures a string member field of a class as a property known to AppSearch. 

@interface Document.TtlMillis

Marks a member field of a document as the document's time-to-live (TTL). 

Public methods

String name()

The schema name of this type.

Inherited methods

Public methods

name

public String name ()

The schema name of this type.

This string is the key to which the complete schema definition is associated in the AppSearch database. It can be specified to replace an existing type with a new definition.

If not specified, it will be automatically set to the simple name of the annotated class.

Returns
String