Search in sources :

Example 1 with MCRSolrIndexHandlerFactory

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;
}
Also used : MCRSolrFilesIndexHandler(org.mycore.solr.index.handlers.stream.MCRSolrFilesIndexHandler) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRPersistenceException(org.mycore.common.MCRPersistenceException) IOException(java.io.IOException) MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRSolrFileIndexHandler(org.mycore.solr.index.handlers.stream.MCRSolrFileIndexHandler) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) Consumer(java.util.function.Consumer) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CONFIG_PREFIX(org.mycore.solr.MCRSolrConstants.CONFIG_PREFIX) MCRSolrIndexHandlerFactory(org.mycore.solr.index.handlers.MCRSolrIndexHandlerFactory) Path(java.nio.file.Path) LogManager(org.apache.logging.log4j.LogManager) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrInputDocument(org.apache.solr.common.SolrInputDocument) IOException(java.io.IOException)

Example 2 with MCRSolrIndexHandlerFactory

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);
    }
}
Also used : MCRPath(org.mycore.datamodel.niofs.MCRPath) Path(java.nio.file.Path) MCRSolrInputDocumentsHandler(org.mycore.solr.index.handlers.document.MCRSolrInputDocumentsHandler) ArrayList(java.util.ArrayList) MCRSolrIndexHandler(org.mycore.solr.index.MCRSolrIndexHandler) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrInputDocument(org.apache.solr.common.SolrInputDocument) MCRSolrIndexHandlerFactory(org.mycore.solr.index.handlers.MCRSolrIndexHandlerFactory) SolrClient(org.apache.solr.client.solrj.SolrClient) MCRPath(org.mycore.datamodel.niofs.MCRPath) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

IOException (java.io.IOException)2 Path (java.nio.file.Path)2 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 MCRPath (org.mycore.datamodel.niofs.MCRPath)2 MCRSolrIndexHandlerFactory (org.mycore.solr.index.handlers.MCRSolrIndexHandlerFactory)2 FileVisitResult (java.nio.file.FileVisitResult)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)1 CONFIG_PREFIX (org.mycore.solr.MCRSolrConstants.CONFIG_PREFIX)1 MCRSolrIndexHandler (org.mycore.solr.index.MCRSolrIndexHandler)1