08-04-2009 10:36 PM
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.Since this is the case, what is a good alternative to PATH queries? What is an efficient query to find all nodes under a particular hierarchy of a specific type with specific property values?
08-05-2009 04:38 AM
10-09-2009 09:38 AM
10-16-2009 08:58 AM
10-22-2009 05:24 AM
(@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);
}
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.