use of org.olat.search.model.OlatDocument 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();
}
use of org.olat.search.model.OlatDocument 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);
}
use of org.olat.search.model.OlatDocument in project openolat by klemens.
the class QuestionItemDocumentFactory method createDocument.
public Document createDocument(SearchResourceContext searchResourceContext, QuestionItemFull item) {
OlatDocument oDocument = new OlatDocument();
oDocument.setId(item.getKey());
oDocument.setCreatedDate(item.getCreationDate());
oDocument.setLastChange(item.getLastModified());
oDocument.setTitle(item.getTitle());
oDocument.setDescription(item.getDescription());
oDocument.setResourceUrl(getResourceUrl(item.getKey()));
oDocument.setDocumentType(QItemDocument.TYPE);
oDocument.setCssIcon("o_qitem_icon");
oDocument.setParentContextType(searchResourceContext.getParentContextType());
oDocument.setParentContextName(searchResourceContext.getParentContextName());
// author
StringBuilder authorSb = new StringBuilder();
List<Identity> owners = qpoolService.getAuthors(item);
for (Identity owner : owners) {
User user = owner.getUser();
authorSb.append(user.getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(user.getProperty(UserConstants.LASTNAME, null)).append(" ");
}
oDocument.setAuthor(authorSb.toString());
// add specific fields
Document document = oDocument.getLuceneDocument();
// content
QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
if (provider != null) {
String content = provider.extractTextContent(item);
if (content != null) {
addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, content, 0.8f);
}
}
if (item.getDescription() != null) {
addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, item.getDescription(), 1.0f);
}
// general fields
addStringField(document, QItemDocument.IDENTIFIER_FIELD, item.getIdentifier(), 1.0f);
addStringField(document, QItemDocument.MASTER_IDENTIFIER_FIELD, item.getMasterIdentifier(), 1.0f);
addTextField(document, QItemDocument.KEYWORDS_FIELD, item.getKeywords(), 2.0f);
addTextField(document, QItemDocument.COVERAGE_FIELD, item.getCoverage(), 2.0f);
addTextField(document, QItemDocument.ADD_INFOS_FIELD, item.getAdditionalInformations(), 2.0f);
addStringField(document, QItemDocument.LANGUAGE_FIELD, item.getLanguage(), 1.0f);
addTextField(document, QItemDocument.TOPIC_FIELD, item.getTopic(), 2.0f);
// educational
if (qpoolModule.isEducationalContextEnabled()) {
if (item.getEducationalContext() != null) {
String context = item.getEducationalContext().getLevel();
addStringField(document, QItemDocument.EDU_CONTEXT_FIELD, context, 1.0f);
}
}
// question
if (item.getType() != null) {
String itemType = item.getType().getType();
addStringField(document, QItemDocument.ITEM_TYPE_FIELD, itemType, 1.0f);
}
addStringField(document, QItemDocument.ASSESSMENT_TYPE_FIELD, item.getAssessmentType(), 1.0f);
// lifecycle
addStringField(document, QItemDocument.ITEM_VERSION_FIELD, item.getItemVersion(), 1.0f);
if (item.getQuestionStatus() != null) {
addStringField(document, QItemDocument.ITEM_STATUS_FIELD, item.getQuestionStatus().name(), 1.0f);
}
// rights
ResourceLicense license = licenseService.loadLicense(item);
if (license != null && license.getLicenseType() != null) {
String licenseKey = String.valueOf(license.getLicenseType().getKey());
addTextField(document, QItemDocument.LICENSE_TYPE_FIELD_NAME, licenseKey, 2.0f);
}
// technical
addTextField(document, QItemDocument.EDITOR_FIELD, item.getEditor(), 2.0f);
addStringField(document, QItemDocument.EDITOR_VERSION_FIELD, item.getEditorVersion(), 1.0f);
addStringField(document, QItemDocument.FORMAT_FIELD, item.getFormat(), 1.0f);
// save owners key
for (Identity owner : owners) {
document.add(new StringField(QItemDocument.OWNER_FIELD, owner.getKey().toString(), Field.Store.NO));
}
// link resources
List<OLATResource> resources = questionItemDao.getSharedResources(item);
for (OLATResource resource : resources) {
document.add(new StringField(QItemDocument.SHARE_FIELD, resource.getKey().toString(), Field.Store.NO));
}
// need pools
List<Pool> pools = poolDao.getPools(item);
for (Pool pool : pools) {
document.add(new StringField(QItemDocument.POOL_FIELD, pool.getKey().toString(), Field.Store.NO));
}
// need path
if (qpoolModule.isTaxonomyEnabled()) {
String path = item.getTaxonomicPath();
if (StringHelper.containsNonWhitespace(path)) {
for (StringTokenizer tokenizer = new StringTokenizer(path, "/"); tokenizer.hasMoreTokens(); ) {
String nextToken = tokenizer.nextToken();
document.add(new TextField(QItemDocument.TAXONOMIC_PATH_FIELD, nextToken, Field.Store.NO));
}
if (item instanceof QuestionItemImpl) {
Long key = ((QuestionItemImpl) item).getTaxonomyLevel().getKey();
TextField field = new TextField(QItemDocument.TAXONOMIC_FIELD, key.toString(), Field.Store.YES);
field.setBoost(3.0f);
document.add(field);
}
}
}
return document;
}
use of org.olat.search.model.OlatDocument in project openolat by klemens.
the class FeedCourseNodeIndexer method doIndex.
/**
* @see org.olat.search.service.indexer.Indexer#doIndex(org.olat.search.service.SearchResourceContext,
* java.lang.Object, org.olat.search.service.indexer.OlatFullIndexer)
*/
@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexer) throws IOException, InterruptedException {
SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, courseNode, getDocumentType());
Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
indexer.addDocument(document);
RepositoryEntry repositoryEntry = courseNode.getReferencedRepositoryEntry();
if (repositoryEntry != null) {
// used for log messages
String repoEntryName = "*name not available*";
try {
repoEntryName = repositoryEntry.getDisplayname();
if (log.isDebug()) {
log.info("Indexing: " + repoEntryName);
}
Feed feed = FeedManager.getInstance().loadFeed(repositoryEntry.getOlatResource());
List<Item> publishedItems = FeedManager.getInstance().loadPublishedItems(feed);
// Create the olatDocument for the feed course node itself
OlatDocument feedNodeDoc = new FeedNodeDocument(feed, courseNodeResourceContext);
indexer.addDocument(feedNodeDoc.getLuceneDocument());
// Only index items. FeedImpl itself is indexed by RepositoryEntryIndexer.
for (Item item : publishedItems) {
OlatDocument itemDoc = new FeedItemDocument(item, courseNodeResourceContext);
indexer.addDocument(itemDoc.getLuceneDocument());
}
} catch (NullPointerException e) {
log.error("Error indexing feed:" + repoEntryName, e);
}
}
}
use of org.olat.search.model.OlatDocument in project openolat by klemens.
the class FeedRepositoryIndexer method doIndex.
/**
* @see org.olat.search.service.indexer.Indexer#doIndex(org.olat.search.service.SearchResourceContext,
* java.lang.Object, org.olat.search.service.indexer.OlatFullIndexer)
*/
@Override
public void doIndex(SearchResourceContext searchResourceContext, Object parentObject, OlatFullIndexer indexer) throws IOException, InterruptedException {
RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
// used for log messages
String repoEntryName = "*name not available*";
try {
repoEntryName = repositoryEntry.getDisplayname();
if (isLogDebugEnabled()) {
logDebug("Indexing: " + repoEntryName);
}
Feed feed = FeedManager.getInstance().loadFeed(repositoryEntry.getOlatResource());
if (feed != null) {
// Only index items. Feed itself is indexed by RepositoryEntryIndexer.
List<Item> publishedItems = FeedManager.getInstance().loadPublishedItems(feed);
if (isLogDebugEnabled()) {
logDebug("PublishedItems size=" + publishedItems.size());
}
for (Item item : publishedItems) {
SearchResourceContext feedContext = new SearchResourceContext(searchResourceContext);
feedContext.setDocumentType(getDocumentType());
OlatDocument itemDoc = new FeedItemDocument(item, feedContext);
indexer.addDocument(itemDoc.getLuceneDocument());
}
}
} catch (NullPointerException e) {
logError("Error indexing feed:" + repoEntryName, e);
}
}
Aggregations