Search in sources :

Example 1 with SearchResourceContext

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

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

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

the class OlatFullIndexer method doIndex.

/**
 * Create index-writer object. In multi-threaded mode ctreates an array of index-workers.
 * Start indexing with main-index as root object. Index recursive all elements.
 * At the end optimize and close new index.
 * The new index is stored in [temporary-index-path]/main
 * @throws InterruptedException
 */
private void doIndex() throws InterruptedException {
    try {
        if (indexerExecutor == null) {
            BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(2);
            indexerExecutor = new ThreadPoolExecutor(indexerPoolSize, indexerPoolSize, 0L, TimeUnit.MILLISECONDS, queue, indexWorkersThreadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
        }
        if (indexerWriterExecutor == null) {
            BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(2);
            indexerWriterExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, queue, indexWriterThreadFactory);
        }
        File tempIndexDir = new File(tempIndexPath);
        Directory tmpIndexPath = FSDirectory.open(new File(tempIndexDir, "main"));
        // analyzer, true, IndexWriter.MAX_TERM_LENGTH.UNLIMITED);
        indexWriter = new IndexWriter(tmpIndexPath, newIndexWriterConfig());
        indexWriter.deleteAll();
        SearchResourceContext searchResourceContext = new SearchResourceContext();
        log.info("doIndex start. OlatFullIndexer with Debug output");
        mainIndexer.doIndex(searchResourceContext, null, /*no parent*/
        this);
        DBFactory.getInstance().commitAndCloseSession();
        log.info("Wait until every folder indexer is finished");
        indexerExecutor.shutdown();
        indexerExecutor.awaitTermination(10, TimeUnit.MINUTES);
        DBFactory.getInstance().commitAndCloseSession();
        log.info("Wait until index writer executor is finished");
        int waitWriter = 0;
        while (indexerWriterExecutor.getActiveCount() > 0 && (waitWriter++ < MAX_WAITING_COUNT)) {
            Thread.sleep(1000);
        }
        log.info("Close index writer executor");
        fullIndexerStatus.setIndexSize(indexWriter.maxDoc());
        // shutdown the index writer thread
        indexerWriterExecutor.submit(new CloseIndexCallable());
        indexerWriterExecutor.shutdown();
        indexerWriterExecutor.awaitTermination(1, TimeUnit.MINUTES);
    } catch (IOException e) {
        log.warn("Can not create IndexWriter, indexname=" + tempIndexPath, e);
    } finally {
        DBFactory.getInstance().commitAndCloseSession();
        log.debug("doIndex: commit & close session");
        if (indexerExecutor != null) {
            indexerExecutor.shutdownNow();
            indexerExecutor = null;
        }
        if (indexerWriterExecutor != null) {
            indexerWriterExecutor.shutdownNow();
            indexerWriterExecutor = null;
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) SearchResourceContext(org.olat.search.service.SearchResourceContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 3 with SearchResourceContext

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

the class GroupIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    long startTime = System.currentTimeMillis();
    final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<BusinessGroup> groupList = bgs.loadAllBusinessGroups();
    if (isLogDebugEnabled())
        logDebug("GroupIndexer groupList.size=" + groupList.size());
    // committing here to make sure the loadBusinessGroup below does actually
    // reload from the database and not only use the session cache
    // (see org.hibernate.Session.get():
    // If the instance, or a proxy for the instance, is already associated with the session, return that instance or proxy.)
    DBFactory.getInstance().commitAndCloseSession();
    // loop over all groups
    for (BusinessGroup businessGroup : groupList) {
        try {
            // reload the businessGroup here before indexing it to make sure it has not been deleted in the meantime
            BusinessGroup reloadedBusinessGroup = bgs.loadBusinessGroup(businessGroup);
            if (reloadedBusinessGroup == null) {
                logInfo("doIndex: businessGroup was deleted while we were indexing. The deleted businessGroup was: " + businessGroup);
                continue;
            }
            businessGroup = reloadedBusinessGroup;
            if (isLogDebugEnabled())
                logDebug("Index BusinessGroup=" + businessGroup);
            SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
            searchResourceContext.setBusinessControlFor(businessGroup);
            Document document = GroupDocument.createDocument(searchResourceContext, businessGroup);
            indexWriter.addDocument(document);
            // Do index child
            super.doIndex(searchResourceContext, businessGroup, indexWriter);
        } catch (Exception ex) {
            logError("Exception indexing group=" + businessGroup, ex);
            DBFactory.getInstance().rollbackAndCloseSession();
        } catch (Error err) {
            logError("Error indexing group=" + businessGroup, err);
            DBFactory.getInstance().rollbackAndCloseSession();
        }
        DBFactory.getInstance().commitAndCloseSession();
    }
    long indexTime = System.currentTimeMillis() - startTime;
    if (isLogDebugEnabled())
        logDebug("GroupIndexer finished in " + indexTime + " ms");
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) SearchResourceContext(org.olat.search.service.SearchResourceContext) Document(org.apache.lucene.document.Document) GroupDocument(org.olat.search.service.document.GroupDocument) IOException(java.io.IOException)

Example 4 with SearchResourceContext

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

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

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

the class ScormCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, NODE_TYPE);
    Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(nodeDocument);
    RepositoryEntry repoEntry = courseNode.getReferencedRepositoryEntry();
    if (repoEntry != null) {
        OLATResource ores = repoEntry.getOlatResource();
        File cpRoot = FileResourceManager.getInstance().unzipFileResource(ores);
        doIndex(courseNodeResourceContext, indexWriter, cpRoot);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) File(java.io.File)

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