Search in sources :

Example 71 with SearchResourceContext

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

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

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

the class QuestionItemIndexer method indexDocument.

@Override
public void indexDocument(List<Long> keyList, LifeFullIndexer indexWriter) {
    QuestionItemDocumentFactory docFactory = CoreSpringFactory.getImpl(QuestionItemDocumentFactory.class);
    List<Document> docs = new ArrayList<>(keyList.size());
    for (Long key : keyList) {
        SearchResourceContext ctxt = new SearchResourceContext();
        Document doc = docFactory.createDocument(ctxt, key);
        docs.add(doc);
    }
    indexWriter.addDocuments(docs);
}
Also used : QuestionItemDocumentFactory(org.olat.modules.qpool.manager.QuestionItemDocumentFactory) SearchResourceContext(org.olat.search.service.SearchResourceContext) ArrayList(java.util.ArrayList) Document(org.apache.lucene.document.Document) QItemDocument(org.olat.modules.qpool.model.QItemDocument)

Example 73 with SearchResourceContext

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

the class QuestionItemIndexer method fullIndex.

@Override
public void fullIndex(LifeFullIndexer indexWriter) {
    QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
    QuestionItemDocumentFactory docFactory = CoreSpringFactory.getImpl(QuestionItemDocumentFactory.class);
    SearchResourceContext ctxt = new SearchResourceContext();
    IndexWriter writer = null;
    try {
        writer = indexWriter.getAndLockWriter();
        int counter = 0;
        List<QuestionItemFull> items;
        do {
            items = qpoolService.getAllItems(counter, BATCH_SIZE);
            for (QuestionItemFull item : items) {
                Document doc = docFactory.createDocument(ctxt, item);
                indexWriter.addDocument(doc, writer);
            }
            counter += items.size();
        } while (items.size() == BATCH_SIZE);
    } catch (Exception e) {
        log.error("", e);
    } finally {
        indexWriter.releaseWriter(writer);
    }
}
Also used : QuestionItemDocumentFactory(org.olat.modules.qpool.manager.QuestionItemDocumentFactory) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolService(org.olat.modules.qpool.QPoolService) SearchResourceContext(org.olat.search.service.SearchResourceContext) IndexWriter(org.apache.lucene.index.IndexWriter) Document(org.apache.lucene.document.Document) QItemDocument(org.olat.modules.qpool.model.QItemDocument)

Example 74 with SearchResourceContext

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

the class GroupForumIndexer method doIndex.

/**
 * Index a forum in a group.
 * @param parentResourceContext
 * @param businessGroup
 * @param indexWriter
 * @throws IOException
 */
@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;
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    ForumManager fom = ForumManager.getInstance();
    Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
    // Check if forum-property exist
    if (forumKeyProperty != null) {
        Long forumKey = forumKeyProperty.getLongValue();
        Forum forum = fom.loadForum(forumKey);
        SearchResourceContext forumSearchResourceContext = new SearchResourceContext(parentResourceContext);
        forumSearchResourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLFORUM);
        forumSearchResourceContext.setDocumentType(TYPE);
        forumSearchResourceContext.setParentContextType(GroupDocument.TYPE);
        forumSearchResourceContext.setParentContextName(businessGroup.getName());
        if (forum == null) {
            // fxdiff: FXOLAT-104 warn about missing forums
            logError("found a forum-key " + forumKey + " for businessgroup " + businessGroup.getName() + " [" + businessGroup.getKey() + "] to index a forum that could not be " + "found by key! skip indexing, check if forum should still be enabled. context: " + forumSearchResourceContext.getResourceUrl(), null);
            return;
        }
        doIndexAllMessages(forumSearchResourceContext, forum, indexWriter);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) ForumManager(org.olat.modules.fo.manager.ForumManager) SearchResourceContext(org.olat.search.service.SearchResourceContext) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) Forum(org.olat.modules.fo.Forum)

Example 75 with SearchResourceContext

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

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)

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