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