String indexName = indexBaseName;
if ( shardName != null ) {
indexName += INDEX_SHARD_ID_SEPARATOR + shardName;
}
IndexManager indexManager = indexManagersRegistry.get( indexName );
if ( indexManager != null ) {
indexManager.addContainedEntity( entityIndexBinding.getDocumentBuilder().getBeanClass() );
return indexManager;
}
SearchFactoryImplementor searchFactory = entityIndexBinding.getSearchFactory();
WorkerBuildContext context;
//known implementations of SearchFactory passed are MutableSearchFactory and ImmutableSearchFactory
if ( WorkerBuildContext.class.isAssignableFrom( searchFactory.getClass() ) ) {
context = (WorkerBuildContext) searchFactory;
}
else {
throw log.assertionFailureCannotCastToWorkerBuilderContext( searchFactory.getClass() );
}
Properties properties = entityIndexBinding.getProperties();
if ( shardName != null ) {
properties = new MaskedProperty( properties, shardName, properties );
}
indexManager = createIndexManager(
indexName,
entityIndexBinding.getDocumentBuilder().getBeanClass(),
entityIndexBinding.getSimilarity(),
properties,
entityIndexBinding.getIndexManagerFactory(),
context
);
indexManager.setSearchFactory( searchFactory );
return indexManager;
}