@Override protected void doWork() { ElasticSearchIndexing esi = Framework.getService(ElasticSearchIndexing.class); openSystemSession(); int bucketSize = Math.min(documentCount, getBucketSize()); List<String> ids = new ArrayList<>(bucketSize); for (DocumentLocation doc : getDocuments()) { ids.add(doc.getIdRef().value); if ((ids.size() % bucketSize) == 0) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } } if (!ids.isEmpty()) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); } if (syncAlias) { log.warn(String.format("Re-indexing job: %s completed.", getSchedulePath().getParentPath())); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esa.syncSearchAndWriteAlias(esa.getIndexNameForRepository(repositoryName)); } }
/** * Index synchronously reordered children. * * @param parentDocument */ public void indexReorderedChildren(DocumentModel parentDocument) { // Filter on trashed and version children Filter filter = new Filter() { private static final long serialVersionUID = 6829091503899474742L; @Override public boolean accept(DocumentModel docModel) { boolean notTrashed = !StringUtils.equals(LifeCycleConstants.DELETED_STATE, docModel.getCurrentLifeCycleState()); return !docModel.isVersion() && notTrashed; } }; // Direct children DocumentModelIterator childrenIterator = this.session.getChildrenIterator(parentDocument.getRef(), null, null, filter); if (childrenIterator != null) { List<IndexingCommand> cmds = new ArrayList<>(2); // Commands while (childrenIterator.hasNext()) { cmds.add(new IndexingCommand(childrenIterator.next(), IndexingCommand.Type.UPDATE, true, false)); } // Synchronous indexing ElasticSearchIndexing esi = (ElasticSearchIndexing) Framework.getService(ElasticSearchIndexing.class); esi.indexNonRecursive(cmds); } }
@Override protected void doIndexingWork(ElasticSearchIndexing esi, List<IndexingCommand> cmds) { long now = Timestamp.currentTimeMicros(); for (IndexingCommand cmd : cmds) { cmd.setOrder(now); } esi.indexNonRecursive(cmds); WorkManager wm = Framework.getService(WorkManager.class); for (IndexingCommand cmd : cmds) { if (needRecurse(cmd)) { wm.schedule(getWorker(cmd)); } } }
@Override protected void doIndexingWork(ElasticSearchIndexing esi, List<IndexingCommand> cmds) { if (cmds.isEmpty()) { return; } IndexingCommand cmd = cmds.get(0); DocumentModel doc = getDocument(cmd); if (doc == null) { return; } DocumentModelIterator iter = session.getChildrenIterator(doc.getRef()); while (iter.hasNext()) { // Add a session save to process cache invalidation session.save(); DocumentModel child = iter.next(); IndexingCommand childCommand = cmd.clone(child); esi.indexNonRecursive(childCommand); if (child.isFolder()) { ChildrenIndexingWorker subWorker = new ChildrenIndexingWorker(childCommand); WorkManager wm = Framework.getService(WorkManager.class); wm.schedule(subWorker); } } }