final Collection<CRResolvableBean> slice, final Map<String, Boolean> attributes, final RequestProcessor rp,
final boolean create, final CRConfigUtil config, final List<ContentTransformer> transformerlist,
final List<String> reverseattributes, final TaxonomyWriter taxonomyWriter, final TaxonomyAccessor taxonomyAccessor)
throws CRException, IOException {
// prefill all needed attributes
UseCase uc = MonitorFactory.startUseCase("indexSlice(" + crid + ")");
try {
CRRequest req = new CRRequest();
String[] prefillAttributes = attributes.keySet().toArray(new String[0]);
req.setAttributeArray(prefillAttributes);
UseCase prefillCase = MonitorFactory.startUseCase("indexSlice(" + crid + ").prefillAttributes");
rp.fillAttributes(slice, req, idAttribute);
prefillCase.stop();
for (Resolvable objectToIndex : slice) {
CRResolvableBean bean = new CRResolvableBean(objectToIndex, prefillAttributes);
UseCase bcase = MonitorFactory.startUseCase("indexSlice(" + crid + ").indexBean");
try {
//CALL PRE INDEX PROCESSORS/TRANSFORMERS
//TODO This could be optimized for multicore servers with
//a map/reduce algorithm
if (transformerlist != null) {
for (ContentTransformer transformer : transformerlist) {
try {
if (transformer.match(bean)) {
String msg = "TRANSFORMER: " + transformer.getTransformerKey() + "; BEAN: " + bean.get(idAttribute);
status.setCurrentStatusString(msg);
ContentTransformer.getLogger().debug(msg);
if (transformer instanceof AbstractLuceneMonitoringTransformer) {
((AbstractLuceneMonitoringTransformer) transformer).processBeanWithMonitoring(bean, indexWriter);
} else {
transformer.processBeanWithMonitoring(bean);
}
}
} catch (Exception e) {
//TODO Remember broken files
log.error("Error while Transforming Contentbean" + "with id: " + bean.get(idAttribute) + " Transformer: "
+ transformer.getTransformerKey() + " " + transformer.getClass().getName(), e);
}
}
}
Term idTerm = new Term(idAttribute, bean.getString(idAttribute));
Document docToUpdate = getUniqueDocument(indexReader, idTerm, crid);
// get the category paths for the facets
CategoryDocumentBuilder categoryDocBuilder = null;
if (useFacets && taxonomyAccessor != null && taxonomyWriter != null) {
List<CategoryPath> categories = getCategoryAttributeMapping(bean, taxonomyAccessor.getTaxonomyMappings());
if (categories.size() > 0) {
categoryDocBuilder = new CategoryDocumentBuilder(taxonomyWriter).setCategoryPaths(categories);
}
}
if (!create && docToUpdate != null) {
Document doc = getDocument(docToUpdate, bean, attributes, config, reverseattributes);
// add facets to document
if (categoryDocBuilder != null) {
categoryDocBuilder.build(doc);
}
indexWriter.updateDocument(idTerm, doc);
} else {
Document doc = getDocument(null, bean, attributes, config, reverseattributes);
// add facets to document
if (categoryDocBuilder != null) {
categoryDocBuilder.build(doc);
}
indexWriter.addDocument(doc);
}
} finally {
bcase.stop();
}
//Stop Indexing when thread has been interrupted
if (Thread.currentThread().isInterrupted()) {
break;
}