Source:
private static List<Contentlet> getPullResults(final Relationship relationship, String contentletIdentifier, final String condition, final int limit, final int offset, String sort, final User user, final String tmDate, final boolean pullByParent) { contentletIdentifier = RecurrenceUtil.getBaseEventIdentifier(contentletIdentifier); StringBuilder pullQuery = new StringBuilder(); try { final Contentlet contentlet = conAPI .findContentletByIdentifierAnyLanguage(contentletIdentifier); final List<Contentlet> relatedContent = conAPI.getRelatedContent(contentlet, relationship, pullByParent, user, false); if (relatedContent.isEmpty()){ return Collections.emptyList(); } pullQuery.append("+identifier:(").append(String.join(" OR ", relatedContent .stream().map(cont -> cont.getIdentifier()).collect( Collectors.toList()))).append(")"); if (UtilMethods.isSet(condition)) { pullQuery.append(" AND ").append(condition); } return pull(pullQuery.toString(), offset, limit, sort, user, tmDate); } catch (Exception e) { Logger.error(ContentUtils.class, "Error pulling related content", e); } return Collections.emptyList(); }

Target:
private static List<Contentlet> getPullResults(final Relationship relationship, String contentletIdentifier, final String condition, final int limit, final int offset, String sort, final User user, final String tmDate, final boolean pullByParent) { final boolean selfRelated = APILocator.getRelationshipAPI().sameParentAndChild(relationship); final String relationshipName = relationship.getRelationTypeValue(); contentletIdentifier = RecurrenceUtil.getBaseEventIdentifier(contentletIdentifier); try { final Contentlet contentlet = conAPI .findContentletByIdentifierAnyLanguage(contentletIdentifier); final StringBuilder pullQuery = new StringBuilder(); if (UtilMethods.isSet(condition)){ if ((selfRelated && pullByParent) || (!selfRelated && relationship .getParentStructureInode().equals(contentlet.getContentTypeId()))) { final List<Contentlet> relatedContent = conAPI .getRelatedContent(contentlet, relationship, pullByParent, user, false); if (relatedContent.isEmpty()) { return Collections.emptyList(); } pullQuery.append("+identifier:(").append(String.join(" OR ", relatedContent .stream().map(cont -> cont.getIdentifier()).collect( Collectors.toList()))).append(")"); if (UtilMethods.isSet(condition)) { pullQuery.append(" AND ").append(condition); } } else { pullQuery.append("+" + relationshipName + ":" + contentletIdentifier); } pullQuery.append(" ").append(condition); return pull(pullQuery.toString(), offset, limit, sort, user, tmDate); } else { String fieldVariable; if ((selfRelated && pullByParent) || (!selfRelated && relationship .getParentStructureInode().equals(contentlet.getContentTypeId()))) { fieldVariable = relationship.getChildRelationName(); } else{ fieldVariable = relationship.getChildRelationName(); } if (relationshipName.contains(StringPool.PERIOD) && contentlet.getContentType() .fieldMap().containsKey(fieldVariable)) { return contentlet.getRelated(fieldVariable, user, false); } return conAPI .getRelatedContent(contentlet, relationship, pullByParent, user, false); } } catch (Exception e) { Logger.error(ContentUtils.class, "Error pulling related content with identifier " + contentletIdentifier + ". Relationship Name: " + relationshipName, e); } return Collections.emptyList(); }