/** * Registers a document type. Typically called by someone * importing the document types from the common Vespa repository. * * @param docType The document type to register. * @return the previously registered type, or null if none was registered */ public DocumentType registerDocumentType(DocumentType docType) { register(docType); return docType; }
/** * Adds a document that can be mapped to this search. * @param source A document that can be mapped to this search. * @return Itself for chaining. */ public SearchDef add(DataType source) { sources.register(source); return this; }
private void registerDefaultDataTypes() { DocumentType superDocType = DataType.DOCUMENT; dataTypes.put(superDocType.getId(), superDocType); documentTypes.put(superDocType.getDataTypeName(), superDocType); Class<? extends DataType> dataTypeClass = DataType.class; for (java.lang.reflect.Field field : dataTypeClass.getFields()) { if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { if (DataType.class.isAssignableFrom(field.getType())) { try { //these are all static final DataTypes listed in DataType: DataType type = (DataType) field.get(null); register(type); } catch (IllegalAccessException e) { //ignore } } } } for (AnnotationType type : AnnotationTypes.ALL_TYPES) { annotationTypeRegistry.register(type); } }
private static void registerArrayType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Arraytype array) { DataType nestedType = manager.getDataType(array.datatype(), ""); ArrayDataType type = new ArrayDataType(nestedType, id); manager.register(type); }
private static void registerWeightedSetType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Weightedsettype wset) { DataType nestedType = manager.getDataType(wset.datatype(), ""); WeightedSetDataType type = new WeightedSetDataType( nestedType, wset.createifnonexistant(), wset.removeifzero(), id); manager.register(type); }
private static void registerMapType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Maptype map) { DataType keyType = manager.getDataType(map.keytype(), ""); DataType valType = manager.getDataType(map.valtype(), ""); MapDataType type = new MapDataType(keyType, valType, id); manager.register(type); }
private static void setupAnnotationRefTypes(DocumentmanagerConfig config, DocumentTypeManager manager) { for (int i = 0; i < config.datatype().size(); i++) { DocumentmanagerConfig.Datatype thisDataType = config.datatype(i); int id = thisDataType.id(); for (Object o : thisDataType.annotationreftype()) { DocumentmanagerConfig.Datatype.Annotationreftype annRefType = (DocumentmanagerConfig.Datatype.Annotationreftype) o; AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annRefType.annotation()); if (annotationType == null) { throw new IllegalArgumentException("Found reference to " + annRefType.annotation() + ", which does not exist!"); } AnnotationReferenceDataType type = new AnnotationReferenceDataType(annotationType, id); manager.register(type); } } }
private static void registerReferenceType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Referencetype refType) { ReferenceDataType referenceType; if (manager.hasDataType(refType.target_type_id())) { DocumentType targetDocType = (DocumentType)manager.getDataType(refType.target_type_id()); referenceType = new ReferenceDataType(targetDocType, id); } else { TemporaryStructuredDataType temporaryTargetType = TemporaryStructuredDataType.createById(refType.target_type_id()); referenceType = new ReferenceDataType(temporaryTargetType, id); } // Note: can't combine the above new-statements, as they call different constructors. manager.register(referenceType); }
@SuppressWarnings("deprecation") private static void registerDocumentType(DocumentTypeManager manager, DocumentmanagerConfig.Datatype.Documenttype doc) { StructDataType header = (StructDataType) manager.getDataType(doc.headerstruct(), ""); StructDataType body = (StructDataType) manager.getDataType(doc.bodystruct(), ""); for (Field field : body.getFields()) { field.setHeader(false); } DocumentType type = new DocumentType(doc.name(), header, body); for (Object j : doc.inherits()) { DocumentmanagerConfig.Datatype.Documenttype.Inherits parent = (DocumentmanagerConfig.Datatype.Documenttype.Inherits) j; DataTypeName name = new DataTypeName(parent.name()); DocumentType parentType = manager.getDocumentType(name); if (parentType == null) { throw new IllegalArgumentException("Could not find document type '" + name.toString() + "'."); } type.inherit(parentType); } manager.register(type); }
private static void registerStructType(DocumentmanagerConfig config, DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Structtype struct) { StructDataType type = new StructDataType(id, struct.name()); if (config.enablecompression()) { CompressionConfig comp = makeCompressionConfig(struct); type.setCompressionConfig(comp); } for (Object j : struct.field()) { DocumentmanagerConfig.Datatype.Structtype.Field field = (DocumentmanagerConfig.Datatype.Structtype.Field) j; DataType fieldType = (field.datatype() == id) ? manager.getDataTypeAndReturnTemporary(field.datatype(), field.detailedtype()) : manager.getDataType(field.datatype(), field.detailedtype()); if (field.id().size() == 1) { type.addField(new Field(field.name(), field.id().get(0).id(), fieldType, true)); } else { type.addField(new Field(field.name(), fieldType, true)); } } manager.register(type); }