Source:
<code>protected void stackCommand(DocumentModel doc, String eventId, boolean sync) { IndexingCommands cmds = getOrCreateCommands(doc); Type type; boolean recurse = false; switch (eventId) { case DOCUMENT_CREATED: case DOCUMENT_IMPORTED: type = Type.INSERT; break; case DOCUMENT_CREATED_BY_COPY: type = Type.INSERT; recurse = isFolderish(doc); break; case BEFORE_DOC_UPDATE: case DOCUMENT_CHECKEDIN: case DOCUMENT_CHECKEDOUT: case BINARYTEXT_UPDATED: case DOCUMENT_TAG_UPDATED: case DOCUMENT_PROXY_UPDATED: case LifeCycleConstants.TRANSITION_EVENT: case DOCUMENT_TRASHED: case DOCUMENT_UNTRASHED: case DOCUMENT_RESTORED: if (doc.isProxy() && !doc.isImmutable()) { stackCommand(doc.getCoreSession().getDocument(new IdRef(doc.getSourceId())), BEFORE_DOC_UPDATE, false); } type = Type.UPDATE; break; case ABOUT_TO_CHECKIN: if (indexIsLatestVersion()) { <START> DocumentModelList versions = doc.getCoreSession().query("SELECT * FROM " + doc.getType() <END> + " WHERE (ecm:isLatestMajorVersion = 1 OR ecm:isLatestVersion = 1) AND ecm:versionVersionableId= '" + doc.getId() + "'"); for (DocumentModel version : versions) { stackCommand(version, BEFORE_DOC_UPDATE, false); } } type = Type.UPDATE; break; case DOCUMENT_MOVED: type = Type.UPDATE; recurse = isFolderish(doc); break; case DOCUMENT_REMOVED: type = Type.DELETE; recurse = isFolderish(doc); break; case DOCUMENT_SECURITY_UPDATED: type = Type.UPDATE_SECURITY; recurse = isFolderish(doc); break; case DOCUMENT_CHILDREN_ORDER_CHANGED: type = Type.UPDATE_DIRECT_CHILDREN; recurse = true; break; default: return; } if (sync && recurse) { cmds.add(type, true, false); cmds.add(type, false, true); } else { cmds.add(type, sync, recurse); } }</code><technical_language>String.format clearer IMO</technical_language>

Target:
protected void stackCommand(DocumentModel doc, String eventId, boolean sync) { IndexingCommands cmds = getOrCreateCommands(doc); Type type; boolean recurse = false; switch (eventId) { case DOCUMENT_CREATED: case DOCUMENT_IMPORTED: type = Type.INSERT; break; case DOCUMENT_CREATED_BY_COPY: type = Type.INSERT; recurse = isFolderish(doc); break; case BEFORE_DOC_UPDATE: case DOCUMENT_CHECKEDIN: case DOCUMENT_CHECKEDOUT: case BINARYTEXT_UPDATED: case DOCUMENT_TAG_UPDATED: case DOCUMENT_PROXY_UPDATED: case LifeCycleConstants.TRANSITION_EVENT: case DOCUMENT_TRASHED: case DOCUMENT_UNTRASHED: case DOCUMENT_RESTORED: if (doc.isProxy() && !doc.isImmutable()) { stackCommand(doc.getCoreSession().getDocument(new IdRef(doc.getSourceId())), BEFORE_DOC_UPDATE, false); } type = Type.UPDATE; break; case ABOUT_TO_CHECKIN: if (indexIsLatestVersion()) { String query = String.format( "SELECT * FROM %s WHERE (ecm:isLatestMajorVersion = 1 OR ecm:isLatestVersion = 1) AND ecm:versionVersionableId= '%s'", doc.getType(), doc.getId()); DocumentModelList versions = doc.getCoreSession().query(query); for (DocumentModel version : versions) { stackCommand(version, BEFORE_DOC_UPDATE, false); } } type = Type.UPDATE; break; case DOCUMENT_MOVED: type = Type.UPDATE; recurse = isFolderish(doc); break; case DOCUMENT_REMOVED: type = Type.DELETE; recurse = isFolderish(doc); break; case DOCUMENT_SECURITY_UPDATED: type = Type.UPDATE_SECURITY; recurse = isFolderish(doc); break; case DOCUMENT_CHILDREN_ORDER_CHANGED: type = Type.UPDATE_DIRECT_CHILDREN; recurse = true; break; default: return; } if (sync && recurse) { cmds.add(type, true, false); cmds.add(type, false, true); } else { cmds.add(type, sync, recurse); } }