Search in sources :

Example 6 with DocumentAccessException

use of org.olat.search.service.document.file.DocumentAccessException in project openolat by klemens.

the class FolderIndexerWorker method doIndexVFSLeaf.

protected void doIndexVFSLeaf(SearchResourceContext leafResourceContext, VFSLeaf leaf, OlatFullIndexer writer, String fPath) {
    if (log.isDebug())
        log.debug("Analyse VFSLeaf=" + leaf.getName());
    try {
        if (docFactory.isFileSupported(leaf)) {
            String myFilePath = fPath + "/" + leaf.getName();
            leafResourceContext.setFilePath(myFilePath);
            Document document = docFactory.createDocument(leafResourceContext, leaf);
            if (document != null) {
                // document which are disabled return null
                writer.addDocument(document);
            }
        } else {
            if (log.isDebug())
                log.debug("Documenttype not supported. file=" + leaf.getName());
        }
    } catch (DocumentAccessException e) {
        if (log.isDebug())
            log.debug("Can not access document." + e.getMessage());
    } catch (InterruptedException e) {
        if (log.isDebug())
            log.debug("InterruptedException: Can not index leaf=" + leaf.getName() + ";" + e.getMessage());
    } catch (IOException ioEx) {
        log.warn("IOException: Can not index leaf=" + leaf.getName(), ioEx);
    } catch (Exception ex) {
        log.warn("Exception: Can not index leaf=" + leaf.getName(), ex);
    }
}
Also used : IOException(java.io.IOException) Document(org.apache.lucene.document.Document) IOException(java.io.IOException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException)

Example 7 with DocumentAccessException

use of org.olat.search.service.document.file.DocumentAccessException in project OpenOLAT by OpenOLAT.

the class LeafIndexer method doIndexVFSLeafByMySelf.

protected void doIndexVFSLeafByMySelf(SearchResourceContext leafResourceContext, VFSLeaf leaf, OlatFullIndexer indexWriter, String filePath) throws InterruptedException {
    if (isLogDebugEnabled())
        logDebug("Analyse VFSLeaf=" + leaf.getName());
    try {
        FileDocumentFactory documentFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
        if (documentFactory.isFileSupported(leaf)) {
            String myFilePath = "";
            if (filePath.endsWith("/")) {
                myFilePath = filePath + leaf.getName();
            } else {
                myFilePath = filePath + "/" + leaf.getName();
            }
            leafResourceContext.setFilePath(myFilePath);
            Document document = documentFactory.createDocument(leafResourceContext, leaf);
            indexWriter.addDocument(document);
        } else {
            if (isLogDebugEnabled())
                logDebug("Documenttype not supported. file=" + leaf.getName());
        }
    } catch (DocumentAccessException e) {
        if (isLogDebugEnabled())
            logDebug("Can not access document." + e.getMessage());
    } catch (IOException ioEx) {
        logWarn("IOException: Can not index leaf=" + leaf.getName(), ioEx);
    } catch (InterruptedException iex) {
        throw new InterruptedException(iex.getMessage());
    } catch (Exception ex) {
        logWarn("Exception: Can not index leaf=" + leaf.getName(), ex);
    }
}
Also used : IOException(java.io.IOException) Document(org.apache.lucene.document.Document) FileDocumentFactory(org.olat.search.service.document.file.FileDocumentFactory) IOException(java.io.IOException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException)

Example 8 with DocumentAccessException

use of org.olat.search.service.document.file.DocumentAccessException in project OpenOLAT by OpenOLAT.

the class AbstractQPoolServiceProvider method extractTextContent.

@Override
public String extractTextContent(QuestionItemFull item) {
    String directory = item.getDirectory();
    VFSContainer itemDir = getFileStorage().getContainer(directory);
    VFSItem file = itemDir.resolve(item.getRootFilename());
    if (file instanceof VFSLeaf) {
        FileDocumentFactory docFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
        SearchResourceContext ctxt = new SearchResourceContext();
        ctxt.setBusinessControlFor(item);
        try {
            String content = null;
            Document doc = docFactory.createDocument(ctxt, (VFSLeaf) file);
            for (IndexableField field : doc.getFields()) {
                if (AbstractOlatDocument.CONTENT_FIELD_NAME.equals(field.name())) {
                    content = field.stringValue();
                }
            }
            return content;
        } catch (IOException e) {
            log.error("", e);
        } catch (DocumentAccessException e) {
            log.warn("", e);
        }
    }
    return null;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) FileDocumentFactory(org.olat.search.service.document.file.FileDocumentFactory) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException)

Example 9 with DocumentAccessException

use of org.olat.search.service.document.file.DocumentAccessException in project openolat by klemens.

the class AbstractQPoolServiceProvider method extractTextContent.

@Override
public String extractTextContent(QuestionItemFull item) {
    String directory = item.getDirectory();
    VFSContainer itemDir = getFileStorage().getContainer(directory);
    VFSItem file = itemDir.resolve(item.getRootFilename());
    if (file instanceof VFSLeaf) {
        FileDocumentFactory docFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
        SearchResourceContext ctxt = new SearchResourceContext();
        ctxt.setBusinessControlFor(item);
        try {
            String content = null;
            Document doc = docFactory.createDocument(ctxt, (VFSLeaf) file);
            for (IndexableField field : doc.getFields()) {
                if (AbstractOlatDocument.CONTENT_FIELD_NAME.equals(field.name())) {
                    content = field.stringValue();
                }
            }
            return content;
        } catch (IOException e) {
            log.error("", e);
        } catch (DocumentAccessException e) {
            log.warn("", e);
        }
    }
    return null;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) FileDocumentFactory(org.olat.search.service.document.file.FileDocumentFactory) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException)

Example 10 with DocumentAccessException

use of org.olat.search.service.document.file.DocumentAccessException in project openolat by klemens.

the class LeafIndexer method doIndexVFSLeafByMySelf.

protected void doIndexVFSLeafByMySelf(SearchResourceContext leafResourceContext, VFSLeaf leaf, OlatFullIndexer indexWriter, String filePath) throws InterruptedException {
    if (isLogDebugEnabled())
        logDebug("Analyse VFSLeaf=" + leaf.getName());
    try {
        FileDocumentFactory documentFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
        if (documentFactory.isFileSupported(leaf)) {
            String myFilePath = "";
            if (filePath.endsWith("/")) {
                myFilePath = filePath + leaf.getName();
            } else {
                myFilePath = filePath + "/" + leaf.getName();
            }
            leafResourceContext.setFilePath(myFilePath);
            Document document = documentFactory.createDocument(leafResourceContext, leaf);
            indexWriter.addDocument(document);
        } else {
            if (isLogDebugEnabled())
                logDebug("Documenttype not supported. file=" + leaf.getName());
        }
    } catch (DocumentAccessException e) {
        if (isLogDebugEnabled())
            logDebug("Can not access document." + e.getMessage());
    } catch (IOException ioEx) {
        logWarn("IOException: Can not index leaf=" + leaf.getName(), ioEx);
    } catch (InterruptedException iex) {
        throw new InterruptedException(iex.getMessage());
    } catch (Exception ex) {
        logWarn("Exception: Can not index leaf=" + leaf.getName(), ex);
    }
}
Also used : IOException(java.io.IOException) Document(org.apache.lucene.document.Document) FileDocumentFactory(org.olat.search.service.document.file.FileDocumentFactory) IOException(java.io.IOException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException)

Aggregations

IOException (java.io.IOException)10 DocumentAccessException (org.olat.search.service.document.file.DocumentAccessException)10 Document (org.apache.lucene.document.Document)8 FileDocumentFactory (org.olat.search.service.document.file.FileDocumentFactory)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 BufferedInputStream (java.io.BufferedInputStream)2 IndexableField (org.apache.lucene.index.IndexableField)2 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)2 PDFTextStripper (org.apache.pdfbox.util.PDFTextStripper)2 LimitedContentWriter (org.olat.core.util.io.LimitedContentWriter)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeafFilter (org.olat.core.util.vfs.filters.VFSLeafFilter)2 DialogElementsManager (org.olat.course.nodes.dialog.DialogElementsManager)2 AbstractOlatDocument (org.olat.search.model.AbstractOlatDocument)2 SearchResourceContext (org.olat.search.service.SearchResourceContext)2 CourseNodeDocument (org.olat.search.service.document.CourseNodeDocument)2 ForumMessageDocument (org.olat.search.service.document.ForumMessageDocument)2 FileContent (org.olat.search.service.document.file.FileContent)2