use of org.olat.search.model.OlatDocument in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class EPAbstractHandler method getIndexerDocument.
@Override
public OlatDocument getIndexerDocument(SearchResourceContext searchResourceContext, AbstractArtefact artefact, EPFrontendManager ePFManager) {
OlatDocument document = new OlatDocument();
Identity author = artefact.getAuthor();
if (author != null) {
document.setAuthor(author.getName());
}
Filter filter = FilterFactory.getHtmlTagAndDescapingFilter();
document.setCreatedDate(artefact.getCreationDate());
document.setTitle(filter.filter(artefact.getTitle()));
document.setDescription(filter.filter(artefact.getDescription()));
document.setResourceUrl(searchResourceContext.getResourceUrl());
document.setDocumentType(searchResourceContext.getDocumentType());
document.setCssIcon(artefact.getIcon());
document.setParentContextType(searchResourceContext.getParentContextType());
document.setParentContextName(searchResourceContext.getParentContextName());
StringBuilder sb = new StringBuilder();
if (artefact.getReflexion() != null) {
sb.append(artefact.getReflexion()).append(' ');
}
getContent(artefact, sb, searchResourceContext, ePFManager);
document.setContent(sb.toString());
return document;
}
use of org.olat.search.model.OlatDocument in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class GlossaryManagerImpl method getIndexerDocument.
/**
* Creates a lucene index document for this glossary
*
* @param repositoryEntry
* @param searchResourceContext
* @return Document the index document
*/
@Override
public Document getIndexerDocument(RepositoryEntry repositoryEntry, SearchResourceContext searchResourceContext) {
GlossaryItemManager gIMgr = GlossaryItemManager.getInstance();
VFSContainer glossaryFolder = getGlossaryRootFolder(repositoryEntry.getOlatResource());
VFSLeaf glossaryFile = gIMgr.getGlossaryFile(glossaryFolder);
if (glossaryFile == null) {
return null;
}
String glossaryContent = gIMgr.getGlossaryContent(glossaryFolder);
// strip all html tags
Filter htmlTagsFilter = FilterFactory.getHtmlTagsFilter();
glossaryContent = htmlTagsFilter.filter(glossaryContent);
// create standard olat index document with this data
OlatDocument glossaryDocument = new OlatDocument();
if (repositoryEntry.getInitialAuthor() != null) {
glossaryDocument.setAuthor(repositoryEntry.getInitialAuthor());
}
if (repositoryEntry.getDisplayname() != null) {
glossaryDocument.setTitle(repositoryEntry.getDisplayname());
}
if (repositoryEntry.getDescription() != null) {
glossaryDocument.setDescription(htmlTagsFilter.filter(repositoryEntry.getDescription()));
}
glossaryDocument.setContent(glossaryContent);
glossaryDocument.setCreatedDate(repositoryEntry.getCreationDate());
glossaryDocument.setLastChange(new Date(glossaryFile.getLastModified()));
glossaryDocument.setResourceUrl(searchResourceContext.getResourceUrl());
glossaryDocument.setDocumentType(searchResourceContext.getDocumentType());
glossaryDocument.setCssIcon("o_FileResource-GLOSSARY_icon");
return glossaryDocument.getLuceneDocument();
}
use of org.olat.search.model.OlatDocument in project openolat by klemens.
the class FileDocumentFactory method getDocumentFromCurrentIndex.
private Document getDocumentFromCurrentIndex(SearchResourceContext leafResourceContext, VFSLeaf leaf) {
try {
String resourceUrl = leafResourceContext.getResourceUrl();
SearchService searchService = CoreSpringFactory.getImpl(SearchServiceImpl.class);
Document indexedDoc = searchService.doSearch(resourceUrl);
if (indexedDoc != null) {
String timestamp = indexedDoc.get(AbstractOlatDocument.TIME_STAMP_NAME);
if (timestamp != null) {
Date indexLastModification = DateTools.stringToDate(timestamp);
Date docLastModificationDate = new Date(leaf.getLastModified());
if (leaf instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
Date metaDate = metaInfo.getMetaLastModified();
if (metaDate != null && metaDate.after(docLastModificationDate)) {
docLastModificationDate = metaDate;
}
}
if (docLastModificationDate.compareTo(indexLastModification) < 0) {
OlatDocument olatDoc = new OlatDocument(indexedDoc);
return olatDoc.getLuceneDocument();
}
}
}
} catch (ServiceNotAvailableException | ParseException | QueryException | java.text.ParseException e) {
log.error("", e);
}
return null;
}
Aggregations