Search in sources :

Example 26 with SearchResourceContext

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

the class RepositoryIndexer method doIndex.

/**
 * Loops over all repository-entries. Index repository meta data.
 * Go further with repository-indexer for certain type if available.
 * @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 parentResourceContext, Object businessObj, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    final Roles roles = new Roles(true, true, true, true, false, true, false);
    final SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
    params.setRoles(roles);
    boolean debug = isLogDebugEnabled();
    // loop over all repository-entries
    // 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.)
    dbInstance.commitAndCloseSession();
    int counter = 0;
    List<RepositoryEntry> repositoryList;
    do {
        repositoryList = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, BATCH_SIZE, true);
        for (RepositoryEntry repositoryEntry : repositoryList) {
            try {
                // reload the repositoryEntry here before indexing it to make sure it has not been deleted in the meantime
                RepositoryEntry reloadedRepositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryEntry.getKey());
                if (reloadedRepositoryEntry == null) {
                    logInfo("doIndex: repositoryEntry was deleted while we were indexing. The deleted repositoryEntry was: " + repositoryEntry);
                    continue;
                }
                if (repositoryEntry.getAccess() == RepositoryEntry.DELETED) {
                    continue;
                }
                repositoryEntry = reloadedRepositoryEntry;
                if (debug) {
                    logDebug("Index repositoryEntry=" + repositoryEntry + "  counter=" + counter++ + " with ResourceableId=" + repositoryEntry.getOlatResource().getResourceableId());
                }
                if (!isOnBlacklist(repositoryEntry.getOlatResource().getResourceableId())) {
                    SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
                    searchResourceContext.setBusinessControlFor(repositoryEntry);
                    searchResourceContext.setTitle(repositoryEntry.getDisplayname());
                    searchResourceContext.setDescription(repositoryEntry.getDescription());
                    Document document = documentFactory.createDocument(searchResourceContext, repositoryEntry);
                    indexWriter.addDocument(document);
                    // Pass created-date & modified-date in context to child indexer because the child have no dates
                    searchResourceContext.setLastModified(repositoryEntry.getLastModified());
                    searchResourceContext.setCreatedDate(repositoryEntry.getCreationDate());
                    // go further with resource
                    Indexer repositoryEntryIndexer = getRepositoryEntryIndexer(repositoryEntry);
                    if (repositoryEntryIndexer != null) {
                        repositoryEntryIndexer.doIndex(searchResourceContext, repositoryEntry, indexWriter);
                    } else if (debug) {
                        // e.g. RepositoryEntry
                        logDebug("No RepositoryEntryIndexer for " + repositoryEntry.getOlatResource());
                    }
                } else {
                    logWarn("RepositoryEntry is on black-list and excluded from search-index, repositoryEntry=" + repositoryEntry, null);
                }
            } catch (Throwable ex) {
                // create meaninfull debugging output to find repo entry that is somehow broken
                String entryDebug = "NULL";
                if (repositoryEntry != null) {
                    entryDebug = "resId::" + repositoryEntry.getResourceableId() + " resTypeName::" + repositoryEntry.getResourceableTypeName() + " resName::" + repositoryEntry.getResourcename();
                }
                logWarn("Exception=" + ex.getMessage() + " for repo entry " + entryDebug, ex);
                dbInstance.rollbackAndCloseSession();
            }
            dbInstance.commitAndCloseSession();
        }
        counter += repositoryList.size();
    } while (repositoryList.size() == BATCH_SIZE);
    if (debug) {
        logDebug("RepositoryIndexer finished.  counter=" + counter);
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) Indexer(org.olat.search.service.indexer.Indexer) SearchResourceContext(org.olat.search.service.SearchResourceContext) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) Document(org.apache.lucene.document.Document)

Example 27 with SearchResourceContext

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

the class ScormRepositoryIndexer method doIndex.

/**
 * @see org.olat.repository.handlers.RepositoryHandler#supportsDownload()
 */
public void doIndex(SearchResourceContext resourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (isLogDebugEnabled())
        logDebug("Index Scorm package...");
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    OLATResource ores = repositoryEntry.getOlatResource();
    File cpRoot = FileResourceManager.getInstance().unzipFileResource(ores);
    resourceContext.setDocumentType(TYPE);
    SearchResourceContext scormContext = new SearchResourceContext(resourceContext);
    doIndex(scormContext, indexWriter, cpRoot);
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File)

Example 28 with SearchResourceContext

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

the class SharedFolderRepositoryIndexer method doIndex.

/**
 * @see org.olat.repository.handlers.RepositoryHandler#supportsDownload()
 */
@Override
public void doIndex(SearchResourceContext resourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    if (isLogDebugEnabled())
        logDebug("Analyse Shared Folder RepositoryEntry...");
    resourceContext.setDocumentType(TYPE);
    VFSContainer sfContainer = SharedFolderManager.getInstance().getSharedFolder(repositoryEntry.getOlatResource());
    // only index if no lockfile found. see OLAT-5724
    if (sfContainer != null && sfContainer.resolve(NO_FOLDER_INDEXING_LOCKFILE) == null) {
        SearchResourceContext folderContext = new SearchResourceContext(resourceContext);
        doIndexVFSContainer(folderContext, sfContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 29 with SearchResourceContext

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

the class WikiRepositoryIndexer method doIndex.

/**
 * @see org.olat.repository.handlers.RepositoryHandler#supportsDownload()
 */
@Override
public void doIndex(SearchResourceContext resourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    if (isLogDebugEnabled())
        logDebug("Analyse Wiki RepositoryEntry...");
    String repoEntryName = "*name not available*";
    try {
        repoEntryName = repositoryEntry.getDisplayname();
        Wiki wiki = WikiManager.getInstance().getOrLoadWiki(repositoryEntry.getOlatResource());
        // loop over all wiki pages
        List<WikiPage> wikiPageList = wiki.getAllPagesWithContent();
        for (WikiPage wikiPage : wikiPageList) {
            try {
                SearchResourceContext wikiContext = new SearchResourceContext(resourceContext);
                wikiContext.setDocumentType(TYPE);
                wikiContext.setFilePath(wikiPage.getPageName());
                Document document = WikiPageDocument.createDocument(wikiContext, wikiPage);
                indexWriter.addDocument(document);
            } catch (Exception e) {
                logError("Error indexing wiki page:" + repoEntryName + " " + (wikiPage == null ? "null" : wikiPage.getPageName()), e);
            }
        }
    } catch (Exception e) {
        logError("Error indexing wiki:" + repoEntryName, e);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) WikiPage(org.olat.modules.wiki.WikiPage) Wiki(org.olat.modules.wiki.Wiki) RepositoryEntry(org.olat.repository.RepositoryEntry) Document(org.apache.lucene.document.Document) WikiPageDocument(org.olat.search.service.document.WikiPageDocument) IOException(java.io.IOException)

Example 30 with SearchResourceContext

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

the class AbstractCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode node, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, node, getType());
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, node);
    indexWriter.addDocument(document);
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument)

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