/*
* Initialize the document builder
* This algorithm seems to be safe for incremental search factories.
*/
private void initDocumentBuilders(SearchConfiguration cfg, BuildContext buildContext) {
ConfigContext context = new ConfigContext( cfg );
initProgrammaticAnalyzers( context, cfg.getReflectionManager() );
initProgrammaticallyDefinedFilterDef( cfg.getReflectionManager() );
final PolymorphicIndexHierarchy indexingHierarchy = factoryState.getIndexHierarchy();
final Map<Class<?>, EntityIndexBinder> documentBuildersIndexedEntities = factoryState.getIndexBindingForEntity();
final Map<Class<?>, DocumentBuilderContainedEntity<?>> documentBuildersContainedEntities = factoryState.getDocumentBuildersContainedEntities();
final Set<XClass> optimizationBlackListedTypes = new HashSet<XClass>();
final Map<XClass, Class> classMappings = initializeClassMappings( cfg, cfg.getReflectionManager() );
//we process the @Indexed classes last, so we first start all IndexManager(s).
final List<XClass> rootIndexedEntities = new LinkedList<XClass>();
for ( Map.Entry<XClass, Class> mapping : classMappings.entrySet() ) {
XClass mappedXClass = mapping.getKey();
Class mappedClass = mapping.getValue();
if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {
if ( mappedXClass.isAbstract() ) {
log.abstractClassesCannotInsertDocuments();
continue;
}
rootIndexedEntities.add( mappedXClass );
indexingHierarchy.addIndexedClass( mappedClass );
}
else {
//FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
//XClass unfortunately is not (yet) genericized: TODO?
final DocumentBuilderContainedEntity<?> documentBuilder = new DocumentBuilderContainedEntity(
mappedXClass, context, cfg.getReflectionManager(), optimizationBlackListedTypes, cfg.getInstanceInitializer()
);
//TODO enhance that, I don't like to expose EntityState
if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
documentBuildersContainedEntities.put( mappedClass, documentBuilder );
}
}
bindFilterDefs( mappedXClass );
//TODO should analyzer def for classes at their same level???
}
IndexManagerHolder indexesFactory = factoryState.getAllIndexesManager();
// Create all IndexManagers, configure and start them:
for ( XClass mappedXClass : rootIndexedEntities ) {
Class mappedClass = classMappings.get( mappedXClass );
MutableEntityIndexBinding mappedEntity = indexesFactory.buildEntityIndexBinding( mappedXClass, mappedClass, cfg, buildContext );
//interceptor might use non indexed state
if ( mappedEntity.getEntityIndexingInterceptor() != null ) {
optimizationBlackListedTypes.add( mappedXClass );
}
// Create all DocumentBuilderIndexedEntity
//FIXME DocumentBuilderIndexedEntity needs to be built by a helper method receiving Class<T> to infer T properly
//XClass unfortunately is not (yet) genericized: TODO?
final DocumentBuilderIndexedEntity<?> documentBuilder =
new DocumentBuilderIndexedEntity(
mappedXClass,
context,
mappedEntity.getSimilarity(),
cfg.getReflectionManager(),
optimizationBlackListedTypes,
cfg.getInstanceInitializer()
);
mappedEntity.setDocumentBuilderIndexedEntity( documentBuilder );
documentBuildersIndexedEntities.put( mappedClass, mappedEntity );
}
disableBlackListedTypesOptimization( classMappings, optimizationBlackListedTypes, documentBuildersIndexedEntities, documentBuildersContainedEntities );
factoryState.setAnalyzers( context.initLazyAnalyzers() );
}