Search in sources :

Example 1 with MCRSolrIndexHandler

use of org.mycore.solr.index.MCRSolrIndexHandler in project mycore by MyCoRe-Org.

the class MCRSolrIndexHandlerFactory method getIndexHandler.

public MCRSolrIndexHandler getIndexHandler(Path file, BasicFileAttributes attrs, SolrClient solrClient, boolean sendContent) throws IOException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Solr: submitting file \"{} for indexing", file);
    }
    MCRSolrIndexHandler indexHandler;
    long start = System.currentTimeMillis();
    if (sendContent) {
        /* extract metadata with tika */
        indexHandler = new MCRSolrFileIndexHandler(file, attrs, solrClient);
    } else {
        SolrInputDocument doc = MCRSolrPathDocumentFactory.getInstance().getDocument(file, attrs);
        indexHandler = new MCRSolrInputDocumentHandler(doc, solrClient);
    }
    long end = System.currentTimeMillis();
    indexHandler.getStatistic().addTime(end - start);
    return indexHandler;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) MCRSolrFileIndexHandler(org.mycore.solr.index.handlers.stream.MCRSolrFileIndexHandler) MCRSolrIndexHandler(org.mycore.solr.index.MCRSolrIndexHandler) MCRSolrInputDocumentHandler(org.mycore.solr.index.handlers.document.MCRSolrInputDocumentHandler)

Example 2 with MCRSolrIndexHandler

use of org.mycore.solr.index.MCRSolrIndexHandler in project mycore by MyCoRe-Org.

the class MCRSolrMCRContentIndexHandler method getSubHandlers.

@Override
public List<MCRSolrIndexHandler> getSubHandlers() {
    MCRSolrIndexHandler mcrSolrIndexHandler = new MCRSolrInputDocumentHandler(document, getSolrClient());
    mcrSolrIndexHandler.setCommitWithin(getCommitWithin());
    return Collections.singletonList(mcrSolrIndexHandler);
}
Also used : MCRSolrIndexHandler(org.mycore.solr.index.MCRSolrIndexHandler) MCRSolrInputDocumentHandler(org.mycore.solr.index.handlers.document.MCRSolrInputDocumentHandler)

Example 3 with MCRSolrIndexHandler

use of org.mycore.solr.index.MCRSolrIndexHandler 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

MCRSolrIndexHandler (org.mycore.solr.index.MCRSolrIndexHandler)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 MCRSolrInputDocumentHandler (org.mycore.solr.index.handlers.document.MCRSolrInputDocumentHandler)2 IOException (java.io.IOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 ArrayList (java.util.ArrayList)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 MCRPath (org.mycore.datamodel.niofs.MCRPath)1 MCRSolrIndexHandlerFactory (org.mycore.solr.index.handlers.MCRSolrIndexHandlerFactory)1 MCRSolrInputDocumentsHandler (org.mycore.solr.index.handlers.document.MCRSolrInputDocumentsHandler)1 MCRSolrFileIndexHandler (org.mycore.solr.index.handlers.stream.MCRSolrFileIndexHandler)1