Search in sources :

Example 1 with OlatFullIndexer

use of org.olat.search.service.indexer.OlatFullIndexer in project OpenOLAT by OpenOLAT.

the class IdentityIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    int counter = 0;
    BaseSecurity secMgr = BaseSecurityManager.getInstance();
    List<Long> identityKeys = secMgr.loadVisibleIdentityKeys();
    if (isLogDebugEnabled())
        logDebug("Found " + identityKeys.size() + " active identities to index");
    DBFactory.getInstance().commitAndCloseSession();
    for (Long identityKey : identityKeys) {
        try {
            // reload the identity here before indexing it to make sure it has not been deleted in the meantime
            Identity identity = secMgr.loadIdentityByKey(identityKey);
            if (identity == null || (identity.getStatus() >= Identity.STATUS_VISIBLE_LIMIT)) {
                logInfo("doIndex: identity was deleted while we were indexing. The deleted identity was: " + identity);
                continue;
            }
            if (isLogDebugEnabled())
                logDebug("Indexing identity::" + identity.getName() + " and counter::" + counter);
            // Create a search context for this identity. The search context will open the users visiting card in a new tab
            SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
            searchResourceContext.setBusinessControlFor(OresHelper.createOLATResourceableInstance(Identity.class, identity.getKey()));
            searchResourceContext.setParentContextType(TYPE);
            // delegate indexing work to all configured indexers
            for (Indexer indexer : getChildIndexers()) {
                indexer.doIndex(searchResourceContext, identity, indexWriter);
            }
            counter++;
        } catch (Exception ex) {
            logWarn("Exception while indexing identity::" + identityKey + ". Skipping this user, try next one.", ex);
            DBFactory.getInstance().rollbackAndCloseSession();
        }
        DBFactory.getInstance().commitAndCloseSession();
    }
    if (isLogDebugEnabled())
        logDebug("IdentityIndexer finished with counter::" + counter);
}
Also used : OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) Indexer(org.olat.search.service.indexer.Indexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) SearchResourceContext(org.olat.search.service.SearchResourceContext) Identity(org.olat.core.id.Identity) IOException(java.io.IOException) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 2 with OlatFullIndexer

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

the class IdentityIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    int counter = 0;
    BaseSecurity secMgr = BaseSecurityManager.getInstance();
    List<Long> identityKeys = secMgr.loadVisibleIdentityKeys();
    if (isLogDebugEnabled())
        logDebug("Found " + identityKeys.size() + " active identities to index");
    DBFactory.getInstance().commitAndCloseSession();
    for (Long identityKey : identityKeys) {
        try {
            // reload the identity here before indexing it to make sure it has not been deleted in the meantime
            Identity identity = secMgr.loadIdentityByKey(identityKey);
            if (identity == null || (identity.getStatus() >= Identity.STATUS_VISIBLE_LIMIT)) {
                logInfo("doIndex: identity was deleted while we were indexing. The deleted identity was: " + identity);
                continue;
            }
            if (isLogDebugEnabled())
                logDebug("Indexing identity::" + identity.getName() + " and counter::" + counter);
            // Create a search context for this identity. The search context will open the users visiting card in a new tab
            SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
            searchResourceContext.setBusinessControlFor(OresHelper.createOLATResourceableInstance(Identity.class, identity.getKey()));
            searchResourceContext.setParentContextType(TYPE);
            // delegate indexing work to all configured indexers
            for (Indexer indexer : getChildIndexers()) {
                indexer.doIndex(searchResourceContext, identity, indexWriter);
            }
            counter++;
        } catch (Exception ex) {
            logWarn("Exception while indexing identity::" + identityKey + ". Skipping this user, try next one.", ex);
            DBFactory.getInstance().rollbackAndCloseSession();
        }
        DBFactory.getInstance().commitAndCloseSession();
    }
    if (isLogDebugEnabled())
        logDebug("IdentityIndexer finished with counter::" + counter);
}
Also used : OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) Indexer(org.olat.search.service.indexer.Indexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) SearchResourceContext(org.olat.search.service.SearchResourceContext) Identity(org.olat.core.id.Identity) IOException(java.io.IOException) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 3 with OlatFullIndexer

use of org.olat.search.service.indexer.OlatFullIndexer 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 4 with OlatFullIndexer

use of org.olat.search.service.indexer.OlatFullIndexer in project OpenOLAT by OpenOLAT.

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)

Aggregations

SearchResourceContext (org.olat.search.service.SearchResourceContext)4 AbstractHierarchicalIndexer (org.olat.search.service.indexer.AbstractHierarchicalIndexer)4 Indexer (org.olat.search.service.indexer.Indexer)4 OlatFullIndexer (org.olat.search.service.indexer.OlatFullIndexer)4 IOException (java.io.IOException)2 Document (org.apache.lucene.document.Document)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 Identity (org.olat.core.id.Identity)2 Roles (org.olat.core.id.Roles)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)2