Search in sources :

Example 81 with SearchResourceContext

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

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 82 with SearchResourceContext

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

the class ProjectBrokerCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, TYPE);
    Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(nodeDocument);
    // go further, index my projects
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    Long projectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, courseNode);
    if (projectBrokerId != null) {
        List<Project> projects = projectBrokerManager.getProjectListBy(projectBrokerId);
        for (Project project : projects) {
            Document document = ProjectBrokerProjectDocument.createDocument(courseNodeResourceContext, project);
            indexWriter.addDocument(document);
        }
    } else {
        log.debug("projectBrokerId is null, courseNode=" + courseNode + " , course=" + course);
    }
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) SearchResourceContext(org.olat.search.service.SearchResourceContext) Document(org.apache.lucene.document.Document) ProjectBrokerProjectDocument(org.olat.search.service.document.ProjectBrokerProjectDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 83 with SearchResourceContext

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

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)

Example 84 with SearchResourceContext

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

the class CourseNodeIndexer method createSearchResourceContext.

public default SearchResourceContext createSearchResourceContext(SearchResourceContext courseResourceContext, CourseNode node, String type) {
    SearchResourceContext courseNodeResourceContext = new SearchResourceContext(courseResourceContext);
    courseNodeResourceContext.setBusinessControlFor(node);
    courseNodeResourceContext.setDocumentType(type);
    if (StringHelper.containsNonWhitespace(node.getShortTitle())) {
        courseNodeResourceContext.setTitle(node.getShortTitle());
    } else if (StringHelper.containsNonWhitespace(node.getLongTitle())) {
        courseNodeResourceContext.setTitle(node.getLongTitle());
    }
    return courseNodeResourceContext;
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext)

Example 85 with SearchResourceContext

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

the class DialogCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, null);
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(document);
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    DialogElementsManager dialogElmsMgr = CoreSpringFactory.getImpl(DialogElementsManager.class);
    List<DialogElement> elements = dialogElmsMgr.getDialogElements(entry, courseNode.getIdent());
    for (DialogElement element : elements) {
        Forum forum = element.getForum();
        doIndexAllMessages(courseNodeResourceContext, forum, indexWriter);
        doIndexFile(element, courseNodeResourceContext, indexWriter);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) DialogElement(org.olat.course.nodes.dialog.DialogElement) RepositoryEntry(org.olat.repository.RepositoryEntry) Document(org.apache.lucene.document.Document) ForumMessageDocument(org.olat.search.service.document.ForumMessageDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) DialogElementsManager(org.olat.course.nodes.dialog.DialogElementsManager) Forum(org.olat.modules.fo.Forum)

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