Search in sources :

Example 21 with SearchResourceContext

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

the class PortfolioMapDocument method getContent.

private static String getContent(PortfolioStructure map, SearchResourceContext resourceContext, StringBuilder sb, Filter filter) {
    sb.append(' ').append(map.getTitle());
    if (StringHelper.containsNonWhitespace(map.getDescription())) {
        sb.append(' ').append(filter.filter(map.getDescription()));
    }
    for (PortfolioStructure child : ePFMgr.loadStructureChildren(map)) {
        getContent(child, resourceContext, sb, filter);
    }
    for (AbstractArtefact artefact : ePFMgr.getArtefacts(map)) {
        String reflexion = artefact.getReflexion();
        if (StringHelper.containsNonWhitespace(reflexion)) {
            sb.append(' ').append(filter.filter(reflexion));
        }
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(AbstractArtefact.class.getSimpleName(), artefact.getKey());
        EPArtefactHandler<?> handler = portfolioModule.getArtefactHandler(artefact.getResourceableTypeName());
        SearchResourceContext artefactResourceContext = new SearchResourceContext(resourceContext);
        artefactResourceContext.setBusinessControlFor(ores);
        OlatDocument doc = handler.getIndexerDocument(artefactResourceContext, artefact, ePFMgr);
        sb.append(' ').append(doc.getContent());
    }
    return sb.toString();
}
Also used : OlatDocument(org.olat.search.model.OlatDocument) OLATResourceable(org.olat.core.id.OLATResourceable) SearchResourceContext(org.olat.search.service.SearchResourceContext) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact)

Example 22 with SearchResourceContext

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

the class GroupWikiIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (!(businessObj instanceof BusinessGroup))
        throw new AssertException("businessObj must be BusinessGroup");
    BusinessGroup businessGroup = (BusinessGroup) businessObj;
    // Index Group Wiki
    if (isLogDebugEnabled())
        logDebug("Analyse Wiki for Group=" + businessGroup);
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup);
    if (collabTools.isToolEnabled(CollaborationTools.TOOL_WIKI)) {
        try {
            Wiki wiki = WikiManager.getInstance().getOrLoadWiki(businessGroup);
            // loop over all wiki pages
            List<WikiPage> wikiPageList = wiki.getAllPagesWithContent();
            for (WikiPage wikiPage : wikiPageList) {
                SearchResourceContext wikiResourceContext = new SearchResourceContext(parentResourceContext);
                wikiResourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLWIKI);
                wikiResourceContext.setDocumentType(TYPE);
                wikiResourceContext.setFilePath(wikiPage.getPageName());
                Document document = WikiPageDocument.createDocument(wikiResourceContext, wikiPage);
                indexWriter.addDocument(document);
            }
        } catch (NullPointerException nex) {
            logWarn("NullPointerException in GroupWikiIndexer.doIndex.", nex);
        }
    } else {
        if (isLogDebugEnabled())
            logDebug("Group=" + businessGroup + " has no Wiki.");
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) SearchResourceContext(org.olat.search.service.SearchResourceContext) WikiPage(org.olat.modules.wiki.WikiPage) CollaborationTools(org.olat.collaboration.CollaborationTools) Wiki(org.olat.modules.wiki.Wiki) WikiPageDocument(org.olat.search.service.document.WikiPageDocument) Document(org.apache.lucene.document.Document)

Example 23 with SearchResourceContext

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

the class IdentityIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    int counter = 0;
    BaseSecurity secMgr = BaseSecurityManager.getInstance();
    List<Long> identityKeys = secMgr.loadVisibleIdentityKeys();
    if (isLogDebugEnabled())
        logDebug("Found " + identityKeys.size() + " active identities to index");
    DBFactory.getInstance().commitAndCloseSession();
    for (Long identityKey : identityKeys) {
        try {
            // reload the identity here before indexing it to make sure it has not been deleted in the meantime
            Identity identity = secMgr.loadIdentityByKey(identityKey);
            if (identity == null || (identity.getStatus() >= Identity.STATUS_VISIBLE_LIMIT)) {
                logInfo("doIndex: identity was deleted while we were indexing. The deleted identity was: " + identity);
                continue;
            }
            if (isLogDebugEnabled())
                logDebug("Indexing identity::" + identity.getName() + " and counter::" + counter);
            // Create a search context for this identity. The search context will open the users visiting card in a new tab
            SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
            searchResourceContext.setBusinessControlFor(OresHelper.createOLATResourceableInstance(Identity.class, identity.getKey()));
            searchResourceContext.setParentContextType(TYPE);
            // delegate indexing work to all configured indexers
            for (Indexer indexer : getChildIndexers()) {
                indexer.doIndex(searchResourceContext, identity, indexWriter);
            }
            counter++;
        } catch (Exception ex) {
            logWarn("Exception while indexing identity::" + identityKey + ". Skipping this user, try next one.", ex);
            DBFactory.getInstance().rollbackAndCloseSession();
        }
        DBFactory.getInstance().commitAndCloseSession();
    }
    if (isLogDebugEnabled())
        logDebug("IdentityIndexer finished with counter::" + counter);
}
Also used : OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) Indexer(org.olat.search.service.indexer.Indexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) SearchResourceContext(org.olat.search.service.SearchResourceContext) Identity(org.olat.core.id.Identity) IOException(java.io.IOException) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 24 with SearchResourceContext

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

the class PortfolioArtefactIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext searchResourceContext, Object object, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
    if (!portfolioModule.isEnabled())
        return;
    Identity identity = (Identity) object;
    // SearchResourceContext resourceContext = new SearchResourceContext(searchResourceContext); // dont do this way, as it would then try to open an artefact over visiting card -> not possible!
    SearchResourceContext resourceContext = new SearchResourceContext();
    resourceContext.setDocumentType(TYPE);
    resourceContext.setParentContextType(null);
    int currentPosition = 0;
    List<AbstractArtefact> artefacts;
    do {
        artefacts = frontendManager.getArtefacts(identity, currentPosition, MAX_RESULTS);
        for (AbstractArtefact artefact : artefacts) {
            OLATResourceable ores = OresHelper.createOLATResourceableInstance(AbstractArtefact.class.getSimpleName(), artefact.getKey());
            EPArtefactHandler<?> handler = portfolioModule.getArtefactHandler(artefact.getResourceableTypeName());
            resourceContext.setBusinessControlFor(ores);
            OlatDocument doc = handler.getIndexerDocument(resourceContext, artefact, frontendManager);
            Identity author = artefact.getAuthor();
            if (author != null && author.getUser() != null) {
                doc.setReservedTo(author.getKey().toString());
            }
            if (doc != null) {
                indexerWriter.addDocument(doc.getLuceneDocument());
            }
        }
        currentPosition += artefacts.size();
    } while (artefacts.size() == MAX_RESULTS);
    super.doIndex(searchResourceContext, object, indexerWriter);
}
Also used : OlatDocument(org.olat.search.model.OlatDocument) SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResourceable(org.olat.core.id.OLATResourceable) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Identity(org.olat.core.id.Identity)

Example 25 with SearchResourceContext

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

the class ImsCPRepositoryIndexer 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 IMS CP RepositoryEntry...");
    resourceContext.setDocumentType(TYPE);
    if (repositoryEntry != null) {
        File cpRoot = FileResourceManager.getInstance().unzipFileResource(repositoryEntry.getOlatResource());
        if (cpRoot != null) {
            SearchResourceContext cpContext = new SearchResourceContext(resourceContext);
            VFSContainer rootContainer = new LocalFolderImpl(cpRoot);
            doIndexVFSContainer(cpContext, rootContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
        }
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

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