Search in sources :

Example 66 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext in project OpenOLAT by OpenOLAT.

the class FileDocumentFactoryTest method testCreateHtmlDocument.

@Test
public void testCreateHtmlDocument() {
    String filePath = "SearchTestFolder";
    String htmlFileName = "test.html";
    String htmlText = "<html><head><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test&nbsp;Text" + // Text = 'Dies ist der Test Text'
    "</body></html>";
    // must include '\u00A0' !!! 19.5.2010/cg
    String text = "Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
    // Create a test HTML File
    OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(rootPath, null);
    OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(filePath, rootFolder);
    VFSLeaf leaf = (VFSLeaf) namedFolder.resolve(htmlFileName);
    if (leaf != null) {
        leaf.delete();
    }
    leaf = namedFolder.createChildLeaf(htmlFileName);
    FileUtils.save(leaf.getOutputStream(false), htmlText, "utf-8");
    try {
        SearchResourceContext resourceContext = new SearchResourceContext();
        resourceContext.setBusinessControlFor(OresHelper.createOLATResourceableType("FileDocumentFactoryTest"));
        resourceContext.setFilePath(filePath + "/" + leaf.getName());
        Document htmlDocument = fileDocumentFactory.createDocument(resourceContext, leaf);
        // 1. Check content
        String content = htmlDocument.get(OlatDocument.CONTENT_FIELD_NAME);
        assertEquals("Wrong HTML content=" + content.trim() + " , must be =" + text.trim(), text.trim(), content.trim());
        // 2. Check resourceUrl
        String resourceUrl = htmlDocument.get(OlatDocument.RESOURCEURL_FIELD_NAME);
        assertEquals("Wrong ResourceUrl", "[FileDocumentFactoryTest:0][path=" + filePath + "/" + htmlFileName + "]", resourceUrl);
        // 3. Check File-Type
        String fileType = htmlDocument.get(OlatDocument.FILETYPE_FIELD_NAME);
        assertEquals("Wrong file-type", "type.file.html", fileType);
    } catch (IOException e) {
        fail("IOException=" + e.getMessage());
    } catch (DocumentAccessException e) {
        fail("DocumentAccessException=" + e.getMessage());
    }
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) SearchResourceContext(org.olat.search.service.SearchResourceContext) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) OlatDocument(org.olat.search.model.OlatDocument) Test(org.junit.Test)

Example 67 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext in project OpenOLAT by OpenOLAT.

the class DocumentPoolIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object object, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
    String taxonomyTreeKey = documentPoolModule.getTaxonomyTreeKey();
    if (StringHelper.isLong(taxonomyTreeKey)) {
        Long taxonomyKey = new Long(taxonomyTreeKey);
        Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(taxonomyKey));
        OLATResourceable docPoolOres = OresHelper.createOLATResourceableInstanceWithoutCheck(getSupportedTypeName(), 0l);
        SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
        searchResourceContext.setBusinessControlFor(docPoolOres);
        searchResourceContext.setTitle(taxonomy.getDisplayName());
        searchResourceContext.setDescription(taxonomy.getDescription());
        searchResourceContext.setLastModified(taxonomy.getLastModified());
        searchResourceContext.setCreatedDate(taxonomy.getCreationDate());
        doIndexTaxonomyLibrary(searchResourceContext, taxonomy, indexerWriter);
    }
}
Also used : TaxonomyRefImpl(org.olat.modules.taxonomy.model.TaxonomyRefImpl) Taxonomy(org.olat.modules.taxonomy.Taxonomy) OLATResourceable(org.olat.core.id.OLATResourceable) SearchResourceContext(org.olat.search.service.SearchResourceContext)

Example 68 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext 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 69 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext 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 70 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext in project openolat by klemens.

the class FileDocumentFactoryTest method testCreateHtmlDocument.

@Test
public void testCreateHtmlDocument() {
    String filePath = "SearchTestFolder";
    String htmlFileName = "test.html";
    String htmlText = "<html><head><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test&nbsp;Text" + // Text = 'Dies ist der Test Text'
    "</body></html>";
    // must include '\u00A0' !!! 19.5.2010/cg
    String text = "Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
    // Create a test HTML File
    OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(rootPath, null);
    OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(filePath, rootFolder);
    VFSLeaf leaf = (VFSLeaf) namedFolder.resolve(htmlFileName);
    if (leaf != null) {
        leaf.delete();
    }
    leaf = namedFolder.createChildLeaf(htmlFileName);
    FileUtils.save(leaf.getOutputStream(false), htmlText, "utf-8");
    try {
        SearchResourceContext resourceContext = new SearchResourceContext();
        resourceContext.setBusinessControlFor(OresHelper.createOLATResourceableType("FileDocumentFactoryTest"));
        resourceContext.setFilePath(filePath + "/" + leaf.getName());
        Document htmlDocument = fileDocumentFactory.createDocument(resourceContext, leaf);
        // 1. Check content
        String content = htmlDocument.get(OlatDocument.CONTENT_FIELD_NAME);
        assertEquals("Wrong HTML content=" + content.trim() + " , must be =" + text.trim(), text.trim(), content.trim());
        // 2. Check resourceUrl
        String resourceUrl = htmlDocument.get(OlatDocument.RESOURCEURL_FIELD_NAME);
        assertEquals("Wrong ResourceUrl", "[FileDocumentFactoryTest:0][path=" + filePath + "/" + htmlFileName + "]", resourceUrl);
        // 3. Check File-Type
        String fileType = htmlDocument.get(OlatDocument.FILETYPE_FIELD_NAME);
        assertEquals("Wrong file-type", "type.file.html", fileType);
    } catch (IOException e) {
        fail("IOException=" + e.getMessage());
    } catch (DocumentAccessException e) {
        fail("DocumentAccessException=" + e.getMessage());
    }
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) SearchResourceContext(org.olat.search.service.SearchResourceContext) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) OlatDocument(org.olat.search.model.OlatDocument) Test(org.junit.Test)

Aggregations

SearchResourceContext (org.olat.search.service.SearchResourceContext)92 Document (org.apache.lucene.document.Document)60 CourseNodeDocument (org.olat.search.service.document.CourseNodeDocument)32 RepositoryEntry (org.olat.repository.RepositoryEntry)26 IOException (java.io.IOException)18 VFSContainer (org.olat.core.util.vfs.VFSContainer)18 File (java.io.File)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 BusinessGroup (org.olat.group.BusinessGroup)12 AssertException (org.olat.core.logging.AssertException)10 OlatDocument (org.olat.search.model.OlatDocument)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)8 IndexWriter (org.apache.lucene.index.IndexWriter)6 Identity (org.olat.core.id.Identity)6 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 OLATResource (org.olat.resource.OLATResource)6 InfoMessageDocument (org.olat.search.service.document.InfoMessageDocument)6 PortfolioMapDocument (org.olat.search.service.document.PortfolioMapDocument)6