use of org.mycore.solr.index.handlers.MCRSolrIndexHandlerFactory in project mycore by MyCoRe-Org.
the class MCRSolrPathDocumentFactory method getDocument.
/**
* Generates a {@link SolrInputDocument} from a {@link MCRPath} instance.
*
* @see MCRSolrFileIndexHandler
* @see MCRSolrFilesIndexHandler
* @see MCRSolrIndexHandlerFactory
*/
public SolrInputDocument getDocument(Path input, BasicFileAttributes attr) throws IOException, MCRPersistenceException {
SolrInputDocument doc = new SolrInputDocument();
Consumer<? super MCRSolrFileIndexAccumulator> accumulate = (accumulator) -> {
LOGGER.debug("{} accumulates {}", accumulator, input);
try {
accumulator.accumulate(doc, input, attr);
} catch (IOException e) {
LOGGER.error("Error in Accumulator!", e);
}
};
ACCUMULATOR_LIST.forEach(accumulate);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("MCRFile {} transformed to:\n{}", input, doc);
}
return doc;
}
use of org.mycore.solr.index.handlers.MCRSolrIndexHandlerFactory in project mycore by MyCoRe-Org.
the class MCRSolrFilesIndexHandler method indexDerivate.
protected void indexDerivate(MCRObjectID derivateID) throws IOException {
MCRPath rootPath = MCRPath.getPath(derivateID.toString(), "/");
final MCRSolrIndexHandlerFactory ihf = MCRSolrIndexHandlerFactory.getInstance();
final List<MCRSolrIndexHandler> subHandlerList = this.subHandlerList;
final List<SolrInputDocument> docs = new ArrayList<>();
final SolrClient solrClient = this.solrClient;
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
boolean sendContent = ihf.checkFile(file, attrs);
try {
if (sendContent) {
subHandlerList.add(ihf.getIndexHandler(file, attrs, solrClient, true));
} else {
SolrInputDocument fileDoc = MCRSolrPathDocumentFactory.getInstance().getDocument(file, attrs);
docs.add(fileDoc);
}
} catch (Exception ex) {
LOGGER.error("Error creating transfer thread", ex);
}
return super.visitFile(file, attrs);
}
});
int fileCount = subHandlerList.size() + docs.size();
LOGGER.info("Sending {} file(s) for derivate \"{}\"", fileCount, derivateID);
if (!docs.isEmpty()) {
MCRSolrInputDocumentsHandler subHandler = new MCRSolrInputDocumentsHandler(docs, solrClient);
subHandler.setCommitWithin(getCommitWithin());
this.subHandlerList.add(subHandler);
}
}
Aggregations