* @param classpathOffset
* @return
*/
protected Indexer create(String dir,String classpathOffset){
Indexer indexer;
IndexingConfig config;
if(classpathOffset != null){
config= new IndexingConfig(dir,classpathOffset){};
} else {
config= new IndexingConfig(dir);
}
//get the mode based on the configured IndexingComponents
EntityDataIterable dataIterable = config.getDataIterable();
EntityIterator idIterator = config.getEntityIdIterator();
EntityDataProvider dataProvider = config.getEntityDataProvider();
EntityScoreProvider scoreProvider = config.getEntityScoreProvider();
IndexingDestination destination = config.getIndexingDestination();
if(destination == null){
log.error("The indexing configuration does not provide an " +
"indexing destination. This needs to be configured by the key " +
"'{}' in the indexing.properties within the directory {}",
IndexingConstants.KEY_INDEXING_DESTINATION,config.getConfigFolder());
throw new IllegalArgumentException("No IndexingDestination present");
}
List<EntityProcessor> processors = config.getEntityProcessors();
if(processors == null){
log.error("The indexing configuration does not provide an " +
"entity processor. This needs to be configured by the key " +
"'{}' in the indexing.properties within the directory {}",
IndexingConstants.KEY_ENTITY_PROCESSOR,config.getConfigFolder());
}
List<EntityProcessor> postProcessors = config.getEntityPostProcessors();
log.info("Present Source Configuration:");
log.info(" - EntityDataIterable: {}",dataIterable);
log.info(" - EntityIterator: {}",idIterator);
log.info(" - EntityDataProvider: {}",dataProvider);
log.info(" - EntityScoreProvider: {}",scoreProvider);
log.info(" - EntityProcessors ({}):",processors.size());
if(postProcessors != null){
log.info(" - EntityPostProcessors ({}):",postProcessors.size());
}
int i=0;
for(EntityProcessor processor : processors){
i++;
log.info(" {}) {}",i,processor);
}
if(dataIterable != null && scoreProvider != null){
// iterate over data and lookup scores
indexer = new IndexerImpl(dataIterable, scoreProvider,
config.getNormaliser(),destination, processors,
config.getIndexedEntitiesIdsFile(),postProcessors);
} else if(idIterator != null && dataProvider != null){
// iterate over id and lookup data
indexer = new IndexerImpl(idIterator,dataProvider,
config.getNormaliser(),destination, processors,
config.getIndexedEntitiesIdsFile(),postProcessors);
} else if(dataIterable != null && idIterator != null){
// create an EntityIterator to EntityScoreProvider adapter
log.info(
"Create Adapter from the configured EntityIterator '{}' to the " +
"required EntityScoreProvider as needed together with the " +
"configured EntityDataIterable '{}'",
idIterator.getClass(), dataIterable.getClass());
indexer = new IndexerImpl(dataIterable,
new EntityIneratorToScoreProviderAdapter(idIterator),
config.getNormaliser(),destination, processors,
config.getIndexedEntitiesIdsFile(),postProcessors);
} else {
log.error("Invalid Indexing Source configuration: ");
log.error(" - To iterate over the data and lookup scores one need to " +
"configure an EntityDataIterable and an EntityScoreProvider ");
log.error(" - To iterate over the Id and and lookup data one need to " +