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();
}
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;
}
}
}
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");
}
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.");
}
}
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);
}
}
Aggregations