As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
Please note: Path queries will be extremely slow if there are more than a few dozen nodes in the result (even if other parts of the query, for instance on the cm:name, will limit the final result to a single node). Therefore, they should be avoided on large repositories, if at all possible.
(@cm:\categories:"workspace://SpacesStore/[cat1]" OR @cm:\categories:"workspace://SpacesStore/[cat2] OR …")
import java.util.Collection; import java.util.Collections; import java.util.LinkedHashSet; import org.alfresco.model.ContentModel; import org.alfresco.repo.search.impl.lucene.LuceneCategoryServiceImpl; import org.alfresco.repo.tenant.TenantService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.RegexQNamePattern; /** * @author dbachem */ public class LuceneCategoryServicePatch extends LuceneCategoryServiceImpl { private NodeService publicNodeService; private TenantService tenantService; // private Logger logger = Logger.getLogger(LuceneCategoryServicePatch.class); /** * just call the super constructor. */ public LuceneCategoryServicePatch() { super(); } /** * Set the node service * * @param publicNodeService */ public void setPublicNodeService(NodeService nodeService) { this.publicNodeService = nodeService; super.setPublicNodeService(nodeService); } /** * Set the tenant service * * @param tenantService */ public void setTenantService(TenantService tenantService) { this.tenantService = tenantService; super.setTenantService(tenantService); } /* * (non-Javadoc) * * @see * org.alfresco.repo.search.impl.lucene.LuceneCategoryServiceImpl#getChildren * (org.alfresco.service.cmr.repository.NodeRef, * org.alfresco.service.cmr.search.CategoryService.Mode, * org.alfresco.service.cmr.search.CategoryService.Depth) */ @Override public Collection<ChildAssociationRef> getChildren(NodeRef categoryRef, Mode mode, Depth depth) { // logger.debug("categoryRef: " + categoryRef.toString()); // logger.debug("mode: " + mode); // logger.debug("depth: " + depth); // some validation if (categoryRef == null) { return Collections.<ChildAssociationRef> emptyList(); } categoryRef = tenantService.getName(categoryRef); // get subCategories from NodeService; otherwise use Lucene (super.getChildren(..)) if (mode == Mode.SUB_CATEGORIES) { // // logger.debug("PATCH: obtain subcategories from NodeService instead of Lucene"); Collection<ChildAssociationRef> result; if (depth.equals(Depth.IMMEDIATE)) { result = publicNodeService.getChildAssocs(categoryRef, ContentModel.ASSOC_SUBCATEGORIES, RegexQNamePattern.MATCH_ALL); } else {// depth.equals(Depth.ANY) result = new LinkedHashSet<ChildAssociationRef>(); collectSubCategoriesDeep(categoryRef, result); } // logger.debug(" –> subcategories: " + result.size()); return result; } else { return super.getChildren(categoryRef, mode, depth); } } private void collectSubCategoriesDeep(NodeRef categoryRef, Collection<ChildAssociationRef> container) { Collection<ChildAssociationRef> results = publicNodeService.getChildAssocs( categoryRef, ContentModel.ASSOC_SUBCATEGORIES, RegexQNamePattern.MATCH_ALL); for (ChildAssociationRef childAssocRef : results) { container.add(childAssocRef); collectSubCategoriesDeep(childAssocRef.getChildRef(), container); } } }