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:
Cloneable
,Comparable<DataType>
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
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDocumentType
(String name) Creates a new document type and registers it with the document type manager.DocumentType
(String name, StructDataType contentStructType) Creates a new document type and registers it with the document type manager.DocumentType
(String name, StructDataType contentStructType, Set<String> importedFieldNames) DocumentType
(String name, Set<String> importedFieldNames) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an field that can be used with this document type.Adds a new field to this document type and returns the new field objectvoid
addFieldSets
(Map<String, Collection<String>> fieldSets) clone()
Provides the Struct describing the fields in the document.Creates a new, empty FieldValue of this typeboolean
Returns an iterator over all fields in this documenttypefieldSet()
Returns an ordered set snapshot of all fields of this documenttype, except the fields of Document.This is identical tofieldSet()
fieldSet}, but in addition extra hidden synthetic fields are returned.getDeclaredStructType
(String name) Get a struct declared in this document only.getField
(int id) Gets the field with the specified id.Gets the field matching a given name.int
All fields defined in the document and its parents This is for internal use UsefieldSet()
instead orfieldSetAll()
if you really want all fieldsReturns the DocumentNames which are directly inherited by this as a read-only collection.getStructType
(String name) Get a struct declared in this document (or any inherited document).boolean
Returns whether this type defines the given field nameint
hashCode()
boolean
hasImportedField
(String fieldName) void
inherit
(DocumentType type) Adds a document to the inherited document types of this.boolean
inherits
(DocumentType superType) Return whether this document type inherits the given document type.boolean
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, List<DataType> seenTypes) removeField
(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
Methods inherited from class com.yahoo.vespa.objects.Identifiable
create, createFromId, deserialize, deserializeOptional, deserializeWithId, equals, getClassId, getRawUtf8Bytes, getUtf8, onDeserialize, onGetClassId, putUtf8, registerClass, registerClass, serialize, serializeOptional, serializeWithId
Methods inherited from class com.yahoo.vespa.objects.Selectable
select, select, selectMembers
-
Field Details
-
DOCUMENT
- See Also:
-
classId
public static final int classId
-
-
Constructor Details
-
DocumentType
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
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 typecontentStructType
- The type of the content struct
-
DocumentType
-
DocumentType
-
-
Method Details
-
clone
-
createFieldValue
Description copied from class:DataType
Creates a new, empty FieldValue of this type- Specified by:
createFieldValue
in classStructuredDataType
-
getValueClass
- Specified by:
getValueClass
in classDataType
-
isValueCompatible
- Specified by:
isValueCompatible
in classDataType
-
contentStruct
Provides the Struct describing the fields in the document.- Returns:
- a struct describing the document fields.
-
getStructType
Get a struct declared in this document (or any inherited document). Returns null if no such struct was found. If multiple possible structs are found in inherited documents, throws exception.- Parameters:
name
- the name of the struct- Returns:
- reference to a struct data type, or null
-
getDeclaredStructType
Get a struct declared in this document only. Returns null if no such struct was found.- Parameters:
name
- the name of the struct- Returns:
- reference to a struct data type, or null
-
register
- Overrides:
register
in classStructuredDataType
-
isA
Check if this document type has the given name, or inherits from a type with that name. -
addField
Adds an field that can be used with this document type.- Parameters:
field
- the field to add
-
addFieldSets
-
addField
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.
-
inherit
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
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
-
inherits
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
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
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
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
-
hasImportedField
-
removeField
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
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
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
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
-
fieldIteratorThisTypeOnly
Returns an iterator over all fields in this documenttype- Returns:
- An iterator for iterating the fields in this documenttype.
-
equals
- 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
-