Search in sources :

Example 16 with OlatDocument

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);
        }
    }
}
Also used : Item(org.olat.modules.webFeed.Item) OlatDocument(org.olat.search.model.OlatDocument) FeedItemDocument(org.olat.modules.webFeed.search.document.FeedItemDocument) SearchResourceContext(org.olat.search.service.SearchResourceContext) FeedNodeDocument(org.olat.modules.webFeed.search.document.FeedNodeDocument) RepositoryEntry(org.olat.repository.RepositoryEntry) FeedNodeDocument(org.olat.modules.webFeed.search.document.FeedNodeDocument) Document(org.apache.lucene.document.Document) OlatDocument(org.olat.search.model.OlatDocument) FeedItemDocument(org.olat.modules.webFeed.search.document.FeedItemDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) Feed(org.olat.modules.webFeed.Feed)

Example 17 with OlatDocument

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;
}
Also used : OlatDocument(org.olat.search.model.OlatDocument) Filter(org.olat.core.util.filter.Filter) Identity(org.olat.core.id.Identity)

Example 18 with OlatDocument

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);
}
Also used : OlatDocument(org.olat.search.model.OlatDocument) SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResourceable(org.olat.core.id.OLATResourceable) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Identity(org.olat.core.id.Identity)

Example 19 with OlatDocument

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();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatDocument(org.olat.search.model.OlatDocument) Filter(org.olat.core.util.filter.Filter) VFSContainer(org.olat.core.util.vfs.VFSContainer) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) Date(java.util.Date)

Example 20 with OlatDocument

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;
}
Also used : ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) QueryException(org.olat.search.QueryException) SearchService(org.olat.search.SearchService) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) ParseException(org.apache.lucene.queryparser.classic.ParseException) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) Date(java.util.Date)

Aggregations

OlatDocument (org.olat.search.model.OlatDocument)20 Document (org.apache.lucene.document.Document)8 SearchResourceContext (org.olat.search.service.SearchResourceContext)8 Identity (org.olat.core.id.Identity)6 OLATResourceable (org.olat.core.id.OLATResourceable)6 Feed (org.olat.modules.webFeed.Feed)6 Item (org.olat.modules.webFeed.Item)6 FeedItemDocument (org.olat.modules.webFeed.search.document.FeedItemDocument)6 Date (java.util.Date)4 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)4 Filter (org.olat.core.util.filter.Filter)4 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 AbstractOlatDocument (org.olat.search.model.AbstractOlatDocument)4 StringTokenizer (java.util.StringTokenizer)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 ParseException (org.apache.lucene.queryparser.classic.ParseException)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2