Package com.yahoo.document
Class DocumentType
- java.lang.Object
-
- com.yahoo.vespa.objects.Selectable
-
- com.yahoo.vespa.objects.Identifiable
-
- com.yahoo.document.DataType
-
- com.yahoo.document.StructuredDataType
-
- com.yahoo.document.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
-
-
Constructor Summary
Constructors Constructor Description DocumentType(java.lang.String name)
Creates a new document type and registers it with the document type manager.DocumentType(java.lang.String name, StructDataType headerType)
Creates a new document type and registers it with the document type manager.DocumentType(java.lang.String name, StructDataType headerType, StructDataType bodyType)
Deprecated.//TODO Will be removed on Vespa 8DocumentType(java.lang.String name, StructDataType headerType, StructDataType bodyType, java.util.Set<java.lang.String> importedFieldNames)
Deprecated.//TODO Will be removed on Vespa 8DocumentType(java.lang.String name, StructDataType headerType, java.util.Set<java.lang.String> importedFieldNames)
DocumentType(java.lang.String name, java.util.Set<java.lang.String> importedFieldNames)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addField(Field field)
Adds an field that can be used with this document type.Field
addField(java.lang.String name, DataType type)
Adds a new field to this document type and returns the new field objectvoid
addFieldSets(java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> fieldSets)
Field
addHeaderField(java.lang.String name, DataType type)
Deprecated.DocumentType
clone()
StructDataType
contentStruct()
Provides the Struct describing the fields in the document.Document
createFieldValue()
Creates a new, empty FieldValue of this typeboolean
equals(java.lang.Object o)
java.util.Iterator<Field>
fieldIteratorThisTypeOnly()
Returns an iterator over all fields in this documenttypejava.util.Set<Field>
fieldSet()
Returns an ordered set snapshot of all fields of this documenttype, except the fields of Document.java.util.Set<Field>
fieldSet(java.lang.String name)
java.util.Set<Field>
fieldSetAll()
This is identical tofieldSet()
fieldSet}, but in addition extra hidden synthetic fields are returned.Field
getField(int id)
Gets the field with the specified id.Field
getField(java.lang.String name)
Gets the field matching a given name.int
getFieldCount()
java.util.Collection<Field>
getFields()
All fields defined in the document and its parents This is for internal use UsefieldSet()
instead orfieldSetAll()
if you really want all fieldsStructDataType
getHeaderType()
Deprecated.use contentStruct insteadjava.util.Set<java.lang.String>
getImportedFieldNames()
java.util.Collection<DocumentType>
getInheritedTypes()
Returns the DocumentNames which are directly inherited by this as a read-only collection.java.lang.Class
getValueClass()
boolean
hasField(java.lang.String name)
Returns whether this type defines the given field nameint
hashCode()
boolean
hasImportedField(java.lang.String fieldName)
void
inherit(DocumentType type)
Adds a document to the inherited document types of this.java.util.ListIterator<DataTypeName>
inheritedIterator()
boolean
inherits(DocumentType superType)
Return whether this document type inherits the given document type.boolean
isA(java.lang.String docTypeName)
Check if this document type has the given name, or inherits from a type with that name.boolean
isValueCompatible(FieldValue value)
void
onSerialize(com.yahoo.vespa.objects.Serializer target)
protected void
register(DocumentTypeManager manager, java.util.List<DataType> seenTypes)
Field
removeField(java.lang.String name)
Removes an field from the DocumentType.void
visitMembers(com.yahoo.vespa.objects.ObjectVisitor visitor)
-
Methods inherited from class com.yahoo.document.StructuredDataType
buildFieldPath, createByReflection, createId, getDataTypeName
-
Methods inherited from class com.yahoo.document.DataType
compareTo, createFieldValue, getArray, getCode, getId, getMap, getName, getPrimitiveType, getTensor, getWeightedSet, getWeightedSet, isAssignableFrom, isMultivalue, isRegistered, lastPredefinedDataTypeId, register, setId, setName, toString
-
-
-
-
Field Detail
-
DOCUMENT
public static final java.lang.String DOCUMENT
- See Also:
- Constant Field Values
-
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 typeheaderType
- 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
-
clone
public DocumentType clone()
-
createFieldValue
public Document createFieldValue()
Description copied from class:DataType
Creates a new, empty FieldValue of this type- Specified by:
createFieldValue
in classStructuredDataType
-
getValueClass
public java.lang.Class getValueClass()
- Specified by:
getValueClass
in classDataType
-
isValueCompatible
public boolean isValueCompatible(FieldValue value)
- Specified by:
isValueCompatible
in classDataType
-
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
-
register
protected void register(DocumentTypeManager manager, java.util.List<DataType> seenTypes)
- Overrides:
register
in classStructuredDataType
-
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 addtype
- 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 addtype
- 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 classStructuredDataType
- 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 classStructuredDataType
- 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 UsefieldSet()
instead orfieldSetAll()
if you really want all fields- Specified by:
getFields
in classStructuredDataType
- 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 tofieldSet()
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.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classStructuredDataType
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classStructuredDataType
-
onSerialize
public void onSerialize(com.yahoo.vespa.objects.Serializer target)
- Overrides:
onSerialize
in classcom.yahoo.vespa.objects.Identifiable
-
visitMembers
public void visitMembers(com.yahoo.vespa.objects.ObjectVisitor visitor)
- Overrides:
visitMembers
in classDataType
-
-