Class DocumentType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<DataType>

    public class DocumentType
    extends StructuredDataType

    A document definition is a list of fields. Documents may inherit other documents, implicitly acquiring their fields as it's own. If a document is not set to inherit any document, it will always inherit the document "document.0".

    Author:
    Thomas Gundersen, bratseth
    See Also:
    Serialized Form
    • Field Detail

      • classId

        public static final int classId
    • Constructor Detail

      • DocumentType

        public DocumentType​(java.lang.String name)
        Creates a new document type and registers it with the document type manager. This will be created as version 0 of this document type. Implicitly registers this with the document type manager. The document type id will be generated as a hash from the document type name.
        Parameters:
        name - The name of the new document type
      • DocumentType

        public DocumentType​(java.lang.String name,
                            StructDataType headerType)
        Creates a new document type and registers it with the document type manager. Implicitly registers this with the document type manager. The document type id will be generated as a hash from the document type name.
        Parameters:
        name - The name of the new document type
        headerType - The type of the header struct
      • DocumentType

        @Deprecated
        public DocumentType​(java.lang.String name,
                            StructDataType headerType,
                            StructDataType bodyType)
        Deprecated.
        //TODO Will be removed on Vespa 8
      • DocumentType

        public DocumentType​(java.lang.String name,
                            StructDataType headerType,
                            java.util.Set<java.lang.String> importedFieldNames)
      • DocumentType

        @Deprecated
        public DocumentType​(java.lang.String name,
                            StructDataType headerType,
                            StructDataType bodyType,
                            java.util.Set<java.lang.String> importedFieldNames)
        Deprecated.
        //TODO Will be removed on Vespa 8
      • DocumentType

        public DocumentType​(java.lang.String name,
                            java.util.Set<java.lang.String> importedFieldNames)
    • Method Detail

      • contentStruct

        public StructDataType contentStruct()
        Provides the Struct describing the fields in the document.
        Returns:
        a struct describing the document fields.
      • getHeaderType

        @Deprecated
        public StructDataType getHeaderType()
        Deprecated.
        use contentStruct instead
      • isA

        public boolean isA​(java.lang.String docTypeName)
        Check if this document type has the given name, or inherits from a type with that name.
      • addField

        public void addField​(Field field)
        Adds an field that can be used with this document type.
        Parameters:
        field - the field to add
      • addFieldSets

        public void addFieldSets​(java.util.Map<java.lang.String,​java.util.Collection<java.lang.String>> fieldSets)
      • addField

        public Field addField​(java.lang.String name,
                              DataType type)
        Adds a new field to this document type and returns the new field object
        Parameters:
        name - The name of the field to add
        type - The datatype of the field to add
        Returns:
        The field created TODO Fix searchdefinition so that exception can be thrown if filed is already registerd.
      • addHeaderField

        @Deprecated
        public Field addHeaderField​(java.lang.String name,
                                    DataType type)
        Deprecated.
        Adds a new header field to this document type and returns the new field object
        Parameters:
        name - The name of the field to add
        type - The datatype of the field to add
        Returns:
        The field created TODO Fix searchdefinition so that exception can be thrown if filed is already registerd
      • inherit

        public void inherit​(DocumentType type)
        Adds a document to the inherited document types of this. If this type is already directly inherited, nothing is done
        Parameters:
        type - An already DocumentType object.
      • getInheritedTypes

        public java.util.Collection<DocumentType> getInheritedTypes()
        Returns the DocumentNames which are directly inherited by this as a read-only collection. If this document type does not explicitly inherit anything, the list will contain the root type 'Document'
        Returns:
        a read-only list iterator containing the name Strings of the directly inherited document types of this
      • inheritedIterator

        public java.util.ListIterator<DataTypeName> inheritedIterator()
      • inherits

        public boolean inherits​(DocumentType superType)
        Return whether this document type inherits the given document type.
        Parameters:
        superType - The documenttype to check if it inherits.
        Returns:
        true if it inherits the superType, false if not
      • getField

        public Field getField​(java.lang.String name)
        Gets the field matching a given name.
        Specified by:
        getField in class StructuredDataType
        Parameters:
        name - the name of a field.
        Returns:
        returns the matching field, or null if not found.
      • getField

        public Field getField​(int id)
        Description copied from class: StructuredDataType
        Gets the field with the specified id.
        Specified by:
        getField in class StructuredDataType
        Parameters:
        id - the id of the field to return.
        Returns:
        the matching field, or null if not found.
      • hasField

        public boolean hasField​(java.lang.String name)
        Returns whether this type defines the given field name
        Parameters:
        name - The name of the field to check if it has
        Returns:
        True if there is a field with the given name.
      • getFieldCount

        public int getFieldCount()
      • getImportedFieldNames

        public java.util.Set<java.lang.String> getImportedFieldNames()
      • hasImportedField

        public boolean hasImportedField​(java.lang.String fieldName)
      • removeField

        public Field removeField​(java.lang.String name)
        Removes an field from the DocumentType.
        Parameters:
        name - The name of the field.
        Returns:
        The field that was removed or null if it did not exist.
      • getFields

        public java.util.Collection<Field> getFields()
        All fields defined in the document and its parents This is for internal use Use fieldSet() instead or fieldSetAll() if you really want all fields
        Specified by:
        getFields in class StructuredDataType
        Returns:
        All fields defined in the document and its parents
      • fieldSet

        public java.util.Set<Field> fieldSet()

        Returns an ordered set snapshot of all fields of this documenttype, except the fields of Document. Only the overridden version will be returned for overridden fields.

        The fields of a document type has a well-defined order which is exhibited in this set: - Fields come in the order defined in the document type definition. - The fields defined in inherited types come before those in the document type itself. - When a field in an inherited type is overridden, the value is overridden, but not the ordering.

        Returns:
        an unmodifiable snapshot of the fields in this type
      • fieldSetAll

        public java.util.Set<Field> fieldSetAll()
        This is identical to fieldSet() fieldSet}, but in addition extra hidden synthetic fields are returned.
        Returns:
        an unmodifiable snapshot of the all fields in this type
      • fieldSet

        public java.util.Set<Field> fieldSet​(java.lang.String name)
      • fieldIteratorThisTypeOnly

        public java.util.Iterator<Field> fieldIteratorThisTypeOnly()
        Returns an iterator over all fields in this documenttype
        Returns:
        An iterator for iterating the fields in this documenttype.
      • onSerialize

        public void onSerialize​(com.yahoo.vespa.objects.Serializer target)
        Overrides:
        onSerialize in class com.yahoo.vespa.objects.Identifiable
      • visitMembers

        public void visitMembers​(com.yahoo.vespa.objects.ObjectVisitor visitor)
        Overrides:
        visitMembers in class DataType