Search in sources :

Example 6 with SearchResourceContext

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

the class GroupPortfolioIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
    if (!portfolioModule.isEnabled())
        return;
    if (!(businessObj instanceof BusinessGroup))
        throw new AssertException("businessObj must be BusinessGroup");
    BusinessGroup businessGroup = (BusinessGroup) businessObj;
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    Property mapKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_PORTFOLIO);
    // Check if portfolio map property exist
    if (mapKeyProperty != null) {
        Long mapKey = mapKeyProperty.getLongValue();
        String version = mapKeyProperty.getStringValue();
        if (version == null || !version.equals("2")) {
            PortfolioStructure map = frontendManager.loadPortfolioStructureByKey(mapKey);
            if (map != null) {
                SearchResourceContext resourceContext = new SearchResourceContext(parentResourceContext);
                resourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLPORTFOLIO);
                resourceContext.setDocumentType(TYPE);
                resourceContext.setParentContextType(GroupDocument.TYPE);
                resourceContext.setParentContextName(businessGroup.getName());
                Document document = PortfolioMapDocument.createDocument(resourceContext, map);
                indexerWriter.addDocument(document);
            }
        }
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) SearchResourceContext(org.olat.search.service.SearchResourceContext) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) PortfolioMapDocument(org.olat.search.service.document.PortfolioMapDocument) Document(org.apache.lucene.document.Document) GroupDocument(org.olat.search.service.document.GroupDocument) Property(org.olat.properties.Property)

Example 7 with SearchResourceContext

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

the class WikiRepositoryIndexer method doIndex.

/**
 * @see org.olat.repository.handlers.RepositoryHandler#supportsDownload()
 */
@Override
public void doIndex(SearchResourceContext resourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    if (isLogDebugEnabled())
        logDebug("Analyse Wiki RepositoryEntry...");
    String repoEntryName = "*name not available*";
    try {
        repoEntryName = repositoryEntry.getDisplayname();
        Wiki wiki = WikiManager.getInstance().getOrLoadWiki(repositoryEntry.getOlatResource());
        // loop over all wiki pages
        List<WikiPage> wikiPageList = wiki.getAllPagesWithContent();
        for (WikiPage wikiPage : wikiPageList) {
            try {
                SearchResourceContext wikiContext = new SearchResourceContext(resourceContext);
                wikiContext.setDocumentType(TYPE);
                wikiContext.setFilePath(wikiPage.getPageName());
                Document document = WikiPageDocument.createDocument(wikiContext, wikiPage);
                indexWriter.addDocument(document);
            } catch (Exception e) {
                logError("Error indexing wiki page:" + repoEntryName + " " + (wikiPage == null ? "null" : wikiPage.getPageName()), e);
            }
        }
    } catch (Exception e) {
        logError("Error indexing wiki:" + repoEntryName, e);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) WikiPage(org.olat.modules.wiki.WikiPage) Wiki(org.olat.modules.wiki.Wiki) RepositoryEntry(org.olat.repository.RepositoryEntry) Document(org.apache.lucene.document.Document) WikiPageDocument(org.olat.search.service.document.WikiPageDocument) IOException(java.io.IOException)

Example 8 with SearchResourceContext

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

the class BCCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (isLogDebugEnabled())
        logDebug("Index Briefcase...");
    BCCourseNode bcNode = (BCCourseNode) courseNode;
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, bcNode, TYPE);
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, bcNode);
    indexWriter.addDocument(document);
    VFSContainer bcContainer = null;
    if (bcNode.getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER)) {
        bcContainer = BCCourseNode.getNodeFolderContainer(bcNode, course.getCourseEnvironment());
    } else {
        String subpath = courseNode.getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH);
        if (subpath != null) {
            VFSItem item = course.getCourseEnvironment().getCourseFolderContainer().resolve(subpath);
            if (item instanceof VFSContainer) {
                bcContainer = new NamedContainerImpl(courseNode.getShortTitle(), (VFSContainer) item);
            }
        }
    }
    if (bcContainer != null) {
        doIndexVFSContainer(courseNodeResourceContext, bcContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    }
}
Also used : BCCourseNode(org.olat.course.nodes.BCCourseNode) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 9 with SearchResourceContext

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

the class PortfolioCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext searchResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (!portfolioModule.isEnabled())
        return;
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(searchResourceContext, courseNode, NODE_TYPE);
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(document);
    PortfolioCourseNode portfolioNode = (PortfolioCourseNode) courseNode;
    RepositoryEntry repoEntry = portfolioNode.getReferencedRepositoryEntry();
    if (repoEntry != null) {
        OLATResource ores = repoEntry.getOlatResource();
        PortfolioStructure element = structureManager.loadPortfolioStructure(ores);
        if (element != null) {
            Document pDocument = PortfolioMapDocument.createDocument(courseNodeResourceContext, element);
            indexWriter.addDocument(pDocument);
        }
    }
}
Also used : PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) SearchResourceContext(org.olat.search.service.SearchResourceContext) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) PortfolioMapDocument(org.olat.search.service.document.PortfolioMapDocument) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument)

Example 10 with SearchResourceContext

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

the class SPCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (log.isDebug())
        log.debug("Index SinglePage...");
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, courseNode, TYPE);
    Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(nodeDocument);
    // The root of the configured single page. Depends on the configuration
    // whether to follow relative links or not. When relative links are
    // followed, the root is the course folder root, if not, it is folder
    // where the configured file is in
    VFSContainer rootContainer;
    // The filename of the configured file relative to the rootContainer
    String chosenFile;
    // Read the course node configuration
    VFSContainer courseFolderContainer = course.getCourseEnvironment().getCourseFolderContainer();
    boolean allowRelativeLinks = courseNode.getModuleConfiguration().getBooleanSafe(SPEditController.CONFIG_KEY_ALLOW_RELATIVE_LINKS);
    String fileName = (String) courseNode.getModuleConfiguration().get(SPEditController.CONFIG_KEY_FILE);
    // *** IF YOU CHANGE THIS LOGIC, do also change it in SinglePageController! ***
    if (allowRelativeLinks) {
        // Case 1: relative links are allowed. The root is the root of the
        // course, the file name is relative to the root
        rootContainer = courseFolderContainer;
        chosenFile = fileName;
    } else {
        // Case 2: relative links are NOT allowed. We have to calculate the
        // new root and remove the relative path to the course folder form
        // the file.
        String startURI = ((fileName.charAt(0) == '/') ? fileName.substring(1) : fileName);
        int sla = startURI.lastIndexOf('/');
        if (sla != -1) {
            // Some subfolder path is detected, create basecontainer from it
            String root = startURI.substring(0, sla);
            startURI = startURI.substring(sla + 1);
            // Create new root folder from the relative folder path
            VFSContainer newroot = (VFSContainer) courseFolderContainer.resolve(root);
            newroot.setParentContainer(null);
            rootContainer = newroot;
        } else {
            // No subpath detected, just use course base container
            rootContainer = courseFolderContainer;
        }
        chosenFile = startURI;
    }
    VFSLeaf leaf = (VFSLeaf) rootContainer.resolve(chosenFile);
    if (leaf != null) {
        String filePath = getPathFor(leaf);
        // Use inherited method from LeafIndexer for the actual indexing of the content
        SearchResourceContext fileContext = new SearchResourceContext(courseNodeResourceContext);
        doIndexVFSLeafByMySelf(fileContext, leaf, indexWriter, filePath);
        if (!indexOnlyChosenFile) {
            if (log.isDebug())
                log.debug("Index sub pages in SP.");
            Set<String> alreadyIndexFileNames = new HashSet<String>();
            alreadyIndexFileNames.add(chosenFile);
            // Check if page has links to subpages and index those as well
            indexSubPages(courseNodeResourceContext, rootContainer, indexWriter, leaf, alreadyIndexFileNames, 0, filePath);
        } else if (log.isDebug()) {
            log.debug("Index only chosen file in SP.");
        }
    } else if (log.isDebug()) {
        log.debug("Can not found choosen file in SP => Nothing indexed.");
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) HashSet(java.util.HashSet)

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