Search in sources :

Example 36 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext in project openolat by klemens.

the class AbstractPortfolioMapIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext searchResourceContext, Object object, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
    if (!portfolioModule.isEnabled())
        return;
    SearchResourceContext resourceContext = new SearchResourceContext();
    int firstResult = 0;
    List<PortfolioStructure> structures = null;
    do {
        structures = frontendManager.getStructureElements(firstResult, 500, getElementType());
        for (PortfolioStructure structure : structures) {
            if (structure instanceof PortfolioStructureMap) {
                PortfolioStructureMap map = (PortfolioStructureMap) structure;
                if (accept(map)) {
                    resourceContext.setDocumentType(getDocumentType());
                    resourceContext.setBusinessControlFor(map.getOlatResource());
                    Document document = PortfolioMapDocument.createDocument(resourceContext, map);
                    indexerWriter.addDocument(document);
                }
            }
        }
        firstResult += structures.size();
    } while (structures != null && structures.size() == BATCH_SIZE);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) SearchResourceContext(org.olat.search.service.SearchResourceContext) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) PortfolioMapDocument(org.olat.search.service.document.PortfolioMapDocument) Document(org.apache.lucene.document.Document)

Example 37 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext 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);
        }
    }
}
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 38 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext 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);
    }
}
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) RepositoryEntry(org.olat.repository.RepositoryEntry) Feed(org.olat.modules.webFeed.Feed)

Example 39 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext in project openolat by klemens.

the class RepositoryEntryLifeIndexer method fullIndex.

@Override
public void fullIndex(LifeFullIndexer indexWriter) {
    SearchResourceContext ctxt = new SearchResourceContext();
    IndexWriter writer = null;
    try {
        writer = indexWriter.getAndLockWriter();
        int counter = 0;
        List<RepositoryEntry> items;
        do {
            items = repositoryEntryDAO.getAllRepositoryEntries(counter, BATCH_SIZE);
            for (RepositoryEntry item : items) {
                Document doc = documentFactory.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);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) IndexWriter(org.apache.lucene.index.IndexWriter) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryDocument(org.olat.search.service.document.RepositoryEntryDocument) Document(org.apache.lucene.document.Document)

Example 40 with SearchResourceContext

use of org.olat.search.service.SearchResourceContext in project openolat by klemens.

the class RepositoryEntryLifeIndexer method indexDocument.

@Override
public void indexDocument(List<Long> keyList, LifeFullIndexer indexWriter) {
    SearchResourceContext ctxt = new SearchResourceContext();
    List<Document> docs = new ArrayList<>(keyList.size());
    for (Long key : keyList) {
        Document doc = documentFactory.createDocument(ctxt, key);
        docs.add(doc);
    }
    indexWriter.addDocuments(docs);
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) ArrayList(java.util.ArrayList) RepositoryEntryDocument(org.olat.search.service.document.RepositoryEntryDocument) Document(org.apache.lucene.document.Document)

Aggregations

SearchResourceContext (org.olat.search.service.SearchResourceContext)92 Document (org.apache.lucene.document.Document)60 CourseNodeDocument (org.olat.search.service.document.CourseNodeDocument)32 RepositoryEntry (org.olat.repository.RepositoryEntry)26 IOException (java.io.IOException)18 VFSContainer (org.olat.core.util.vfs.VFSContainer)18 File (java.io.File)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 BusinessGroup (org.olat.group.BusinessGroup)12 AssertException (org.olat.core.logging.AssertException)10 OlatDocument (org.olat.search.model.OlatDocument)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)8 IndexWriter (org.apache.lucene.index.IndexWriter)6 Identity (org.olat.core.id.Identity)6 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 OLATResource (org.olat.resource.OLATResource)6 InfoMessageDocument (org.olat.search.service.document.InfoMessageDocument)6 PortfolioMapDocument (org.olat.search.service.document.PortfolioMapDocument)6